当我尝试使用以下代码时,我会得到意想不到的结果 这是我的代码: def copy_blanks(df,column):
if (str.substring(0,1).equals("x") )
PLease建议我。我认为问题是通过这个代码[df.loc [df.iloc [:,column] =='',-1] ='&# 39;]
答案 0 :(得分:0)
IIUC您需要fillna
将print (df)
word number
0 abc 0
1 adf 0
2 gfsgs 0
3 NaN 0
4 sdfgsd 0
5 fgsdfg 0
6 sfdgs 0
def copy_blanks(df, column):
df['new'] = df.iloc[:, column]
df['new'] = df['new'].fillna('')
return df
column = 0
print (copy_blanks(df, column))
word number new
0 abc 0 abc
1 adf 0 adf
2 gfsgs 0 gfsgs
3 NaN 0
4 sdfgsd 0 sdfgsd
5 fgsdfg 0 fgsdfg
6 sfdgs 0 sfdgs
替换为空字符串:
{{1}}