2024-09-27 19:11:46 发布
网友
我有以下数据帧:
>>>name location problems 0 Lena Haifa ,, 1 Layla Aman not enough points 2 Dili Istanbul , ...
如果少于5个字母,我想更改单元格内容, 所以我会得到这张桌子:
>>>name location problems 0 Lena Haifa 1 Layla Aman not enough points 2 Dili Istanbul ...
(请记住,)
我该怎么做
使用分配功能:
df = df.assgin(problem = lambda x: np.where(x['problem'].str.len()< 5,'',x['problem']))
下面是使用np.where的另一种方法:
np.where
df['problems'] = np.where(df['problems'].str.len() < 5, '', df['problems']) print(df) name location problems 0 Lena Haifa 1 Layla Aman not enough points 2 Dili Istanbul
试着这样做:
df.loc[df['problems'].str.len()<5,'problems'] = ''
使用分配功能:
下面是使用
np.where
的另一种方法:试着这样做:
相关问题 更多 >
编程相关推荐