[問題] 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