我有CSV
df = pd.read_csv('data.csv')
表格:
| A列|B栏|C列|
| - -|- -|- -|
| 小行星4068744| -1472525年|小行星2596|
| 小行星198366|- -|- -|
文件正在使用'-'表示nul值
我试着转换成int,但不行程那个'-'。
我的问题是:我如何去掉字符串'-'而不改变负值?
df['Column B'] = df['Column B'].astype(int)
ValueError:基数为10的int()的文字无效:'-'
1条答案
按热度按时间yquaqz181#
pandas
的更高版本可以容纳缺少值的integer
dtype。普通int
转换不支持空值。输出: