我有一个CSV,有两个分隔符(;
)和(,
),它看起来像这样:
vin;vorgangid;eventkm;D_8_lamsoni_w_time;D_8_lamsoni_w_value
V345578;295234545;13;-1000.0,-980.0;7.9921875,11.984375
V346670;329781064;13;-960.0,-940.0;7.9921875,11.984375
我想将它导入到pandas数据框中,其中(;
)充当列分隔符,(,
)作为list
或{float
作为数据类型。到目前为止,我使用的是这种方法,但我相信还有更简单的方法。在
从这里的其他更好的答案来看,更具体的是pandas,需要注意的是,Python本身在字符串处理方面非常强大。您只需将} 对象中,然后从那里正常工作:
';'
替换为','
的结果放在^{首先使用
;
作为分隔符读取CSV:更新:
^{pr2}$旧答案:
现在,我们可以将数字拆分为“数字”列中的列表:
您可以在^{} 中使用参数
converters
,并定义用于拆分的自定义函数:另一个在
4.
和5.
列中使用NaN
的解决方案:您可以将^{} 与分隔符} 应用于^{} 选择的{cd4>}和{}列,并将
^{pr2}$;
一起使用,然后将^{list
中的每个值转换为float
:如果需要}:
numpy arrays
而不是{我试着改进你的解决方案:
相关问题 更多 >
编程相关推荐