熊猫通过分隔符将每一行分为两列(5GB CSV)

时间:2020-09-03 09:20:24

标签: python python-3.x pandas

相对较新,尝试使用python从CSV文件中拆分一些数据。 我的数据结构如下:

Time| Signature
--------------------
0   | Class1#Method1
1   | Class4#Method5
2   | Class5# <--note that Class 5 has no method

我试图完成的是操纵数据集,使其变为

Time| Class  | Method
--------------------
0   | Class1 | Method1
1   | Class4 | Method5

第5类在拆分过程中被删除,因为它没有方法。

我试图遍历整个数据集-可以,但是在处理5gb的csv文件时非常慢。有谁有更快的方法?速度才是最重要的

1 个答案:

答案 0 :(得分:1)

您可能可以使用类似df[['Class','Method']] = df['Signature'].str.split('#',expand=True)

(来自splitting a column by delimiter pandas python