运行python2.7
问题1
我想在数据框“ test”中将空字符串“”替换为“ None”:
from numpy.random import randn
test = pd.DataFrame(randn(3,2))
test.iloc[0,0]=''
test.replace('', None)
给我错误TypeError:
无法将['']替换为DataFrame上的方法垫。
什么地方出了错?
问题2:
从numpy.random导入randn
test = pd.DataFrame(randn(3,2))
# this works
test.iloc[0,1]= 'A'
test[1] = test[1].replace('A','b')
# this does not
test.iloc[0,0]=''
test.loc[0] = test[0].replace('', None)
test
0 1
0 b
1 0.042052 -1.44156
2 0.462131 -0.303288
我期待着
test
0 1
0 None b
1 0.042052 -1.44156
2 0.462131 -0.303288
心有法竹
UYOU
相关分类