3
我已经了解了各种解决方案,并试图解决方案在这里说:Pandas: Converting to numeric, creating NaNs when necessary转换一列浮动
但它并没有真正解决我的问题: 我有一个数据帧中包含多列,在一列['PricePerSeat_Outdoor']
包含一些浮点值,一些空值,有的'-'
print type(df_raw['PricePerSeat_Outdoor'][99])
print df_raw['PricePerSeat_Outdoor'][95:101]
df_raw['PricePerSeat_Outdoor'] = df_raw['PricePerSeat_Outdoor'].apply(pd.to_numeric, errors='coerce')
print type(df_raw['PricePerSeat_Outdoor'][99])
然后我:
<type 'str'>
95 17.21
96 17.24
97 -
98 -
99 17.2
100 17.24
Name: PricePerSeat_Outdoor, dtype: object
<type 'str'>
#98和99行的值未被转换。再次,我已经尝试了多种方法,包括跟随,但它只是没有工作。非常感谢,如果有人可以给我一些提示。
df_raw['PricePerSeat_Outdoor'] = df_raw['PricePerSeat_Outdoor'].apply(pd.to_numeric, errors='coerce')
另外,我怎么能转换成多列数字一次?谢谢。
是的,这就是我终于用...谢谢! – Kevin
但是,你碰巧知道我应该如何应用多列? – Kevin
@凯文,我已经添加了一个例子 - 请检查 – MaxU