[问题] DataFrame replace "," None 问题

楼主: loser113 (洨大鲁蛇ㄍ)   2020-05-27 20:11:52
https://imgur.com/HSz1z2L
目标 想让"," 换成空值
无法直接replace None (没反应)
用了np.nan型态会变成float (我要int)
请指教谢谢 附上代码
import pandas as pd
df = pd.DataFrame({'A': [',', 2], 'B': [0, 2]},)
df
df.replace(",",None)
df.replace(",",pd.np.nan)['A']
作者: cuteSquirrel (松鼠)   2020-05-27 22:02:00
可参考看看: https://bit.ly/2X6rYyZ
作者: ANIO1021 (北上打拼)   2020-05-27 23:09:00
用re取代看看
作者: skyconquer (梅郭曲)   2020-05-28 01:13:00
试试这个: df.replace(",", pd.NA)
楼主: loser113 (洨大鲁蛇ㄍ)   2020-05-29 09:43:00
感谢

Links booklink

Contact Us: admin [ a t ] ucptt.com