Pythonで欠損値(NaNやNone)あるいは特定の文字列("aaa")を1つでも含んだGroupをGroupごとdropしたいのですが方法がわかりません。
Python
1data = [ 2... ('Apple', 'Fruit'), 3... ('Beetroot', 'Vegetable'), 4... ('Carrot', 'Vegetable'), 5... ('Date', 'Fruit'), 6... ('Eggplant', 'Vegetable'), 7... ('Fig', 'Fruit'), 8... ('Apple', 'aaa'), 9... ('Beetroot', ), 10... ('Carrot', 'Vegetable'), 11... ('Date', 'Fruit'), 12... ('Eggplant', 'Vegetable'), 13... ('Fig', 'aaa'),] 14 15df = pd.DataFrame(data, columns=['name', 'category']) 16gdf = df.groupby('name') 17 18gdf_test=gdf.apply(lambda x: x.dropna() if x.item()=='aaa' else x.item()) ##error 19
賢い方どうか教えていただけると幸いです。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/24 07:29