用于更新的Python Pandas lambda列
lambda x: np.nan if x == '0/0' else df['RatioFraction']
过滤一列,然后使用lambda更改np.nan
的条件,不投票(0/0)。
已收到
TypeError: object of type 'float' has no len()
代码:
df['RatioFraction'] = df_ff_reviews['VoteRatio'].apply(lambda x: np.nan if x == '0/0' else df['RatioFraction'])
答案 0 :(得分:1)
尝试一下:
df['RatioFraction'] = df_ff_reviews['VoteRatio']
df['RatioFraction'].loc[df['RatioFraction'] == '0/0'] = np.nan
答案 1 :(得分:0)
您可以尝试np.where:
df['RatioFraction'] = np.where(df['VoteRatio'] == '0/0', np.nan, df['VoteRation'])