I have a question for Python Pandas (if you can use sql, please let me know)(Crying)

Asked 2 years ago, Updated 2 years ago, 57 views

Let's say there's a data frame like this

How do I extract more than one value from the column Alphabet?(c, d, e have only one value, so include X)

python pandas sql dataframe

2022-09-22 18:22

1 Answers

Please refer to the sample below.

import pandas as pd

df = pd.DataFrame(data={'alphabet':['a', 'a', 'a', 'b', 'b', 'c'], 'NNN':range(6), 'MMM':range(6)})
df.groupby('alphabet').filter(lambda x: x['alphabet'].count() > 1)

    alphabet    NNN MMM
0   a   0   0
1   a   1   1
2   a   2   2
3   b   3   3
4   b   4   4


2022-09-22 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.