我有一个文本文件,我想将每一列分开。但是熊猫把全文当作一栏:
6/1/2018 12:01:11.490 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump
runing On
6/1/2018 12:01:19.383 AM HEP.COM.WAT.DRN.P1_CRTL Control No.1 drainage
pump On
6/1/2018 12:01:19.384 AM HEP.COM.WAT.DRN.P1_RUN No.1 drainage pump run
On
6/1/2018 12:01:24.250 AM HEP.U02.OIL.GOV.LV_TL <Unit #2>Oil level of
sump too low Off
6/1/2018 12:01:24.859 AM HEP.U02.OIL.GOV.P2_RUN <Unit #2>No.2 oil pump
runing Off
6/1/2018 12:02:07.564 AM HEP.U02.OIL.GOV.LV_TL <Unit #2>Oil level of
sump too low On
这是我的数据的样子:
import re
import pandas as pd
p=[]
df=pd.read_csv('./mine.txt',encoding='ISO-8859-1', sep='delimeter',
engine='python' ,nrows=100)
print(df.shape)
df=df.columns.str.split('\t')
print(list(df))
print(df.shape)
df.shape()
在(100,1)
之前返回(1,)
,在str.split()
之后返回this.getTableSize = function (tableElement, rowSelector, columnSelector) {
return Promise.all([tableElement.all(rowSelector).count(), tableElement.all(columnSelector).count()]).then(function(data) {
return {
row: data[0],
column: data[1]
}
})
};
tableActions.getTableSize(table, by.css("tr"), by.css("th")).then(function (obj) {
console.log(obj);
})
如何分隔这些列?
答案 0 :(得分:0)
您要在制表符(而不是空格)上分离数据。如果您的文件为.tsv(制表符分隔的值),则将很有意义。您应使用“ \ t”将其分隔,但如果不是,则应使用“ \ s”将空格(而非制表符)分隔。这就是为什么只在str.split(“ \ t”)之后得到(1,)。