Skip to content

Implemented DataFrame.lookup#1785

Open
itholic wants to merge 12 commits intodatabricks:masterfrom
itholic:f_lookup
Open

Implemented DataFrame.lookup#1785
itholic wants to merge 12 commits intodatabricks:masterfrom
itholic:f_lookup

Conversation

@itholic
Copy link
Copy Markdown
Contributor

@itholic itholic commented Sep 22, 2020

This PR proposes DataFrame.lookup.

>>> kdf = ks.DataFrame({'A': [3, 4, 5, 6, 7],
...                     'B': [10.0, 20.0, 30.0, 40.0, 50.0],
...                     'C': ['a', 'b', 'c', 'd', 'e']})
>>> kdf
   A     B  C
0  3  10.0  a
1  4  20.0  b
2  5  30.0  c
3  6  40.0  d
4  7  50.0  e

>>> kdf.lookup([0], ["C"])
array(['a'], dtype=object)

>>> kdf.lookup([2, 3], ["A", "B"])
array([ 5., 40.])

Comment thread databricks/koalas/frame.py Outdated
Comment thread databricks/koalas/frame.py Outdated
Comment thread databricks/koalas/frame.py
@itholic
Copy link
Copy Markdown
Contributor Author

itholic commented Sep 24, 2020

Thanks, @HyukjinKwon

Comment thread databricks/koalas/tests/test_dataframe.py
Comment thread databricks/koalas/frame.py Outdated
@itholic
Copy link
Copy Markdown
Contributor Author

itholic commented Sep 26, 2020

Thanks, @ueshin

raise ValueError("Row labels must have same size as column labels")
lookups = [
self.loc[row_label, col_label]
for row_label, col_label in zip(row_labels, col_labels)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we launch jobs as many as labels?

Comment thread databricks/koalas/frame.py Outdated
self.loc[row_label, col_label] for row_label, col_label in zip(row_labels, col_labels)
]
return Series(lookups).to_numpy()
return np.asarray(pd.Series(lookups))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why did we change it to np.asarray(pd.Series(lookups))?

@xinrong-meng
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants