我有以下代码:
data_agg_df = data_df.groupby("team", as_index=False).player.agg({"player_set": lambda x: set(list(x)), "player_count": "nunique"})
然后我的结果如下:
team player_set player_count
-------------------------------------------------
A {John, Mary} 2
B {nan} 0
C {Dave,nan} 1
我想知道怎么不在player_set中显示nana?即我希望结果数据框看起来像:
team player_set player_count
-------------------------------------------------
A {John, Mary} 2
B {} 0
C {Dave} 1
谢谢!
答案 0 :(得分:1)
替换
set(list(x))
带
set(list(i for i in x if pd.notnull(i)))
取出nan
s