Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request for using lambda inside of .loc[] #2200

Open
kylegilde opened this issue Sep 23, 2021 · 0 comments
Open

Feature Request for using lambda inside of .loc[] #2200

kylegilde opened this issue Sep 23, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@kylegilde
Copy link

kylegilde commented Sep 23, 2021

Hello!

Would you consider adding the ability to self-reference DataFrames and Series using the lambda function inside of the .loc[] method? I think it's one of the most convenient features in Pandas.

Thank you

import panda as pd
my_df = pd.DataFrame(
    {
        "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")),
        "b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")),
        "c": pd.Series([True, False, np.nan], dtype=np.dtype("O")),
        "d": pd.Series(["h", "i", np.nan], dtype=np.dtype("O")),
        "e": pd.Series([10, np.nan, 20], dtype=np.dtype("float")),
        "f": pd.Series([np.nan, 100.5, 200], dtype=np.dtype("float")),
    }
)
print(my_df.loc[lambda df: (df.a == 3) | (df.b == 'x')])
   a  b     c    d    e     f
0  1  x  True    h 10.0   NaN
2  3  z   NaN  NaN 20.0 200.0
print(my_df.a.loc[lambda s: s < 2])
0    1
Name: a, dtype: int32
@itholic itholic added the enhancement New feature or request label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants