我正在尝试解析文本文件并将其加载到数据框中。我得到了从堆栈溢出解析文本文件但有一些调整的帮助。我将文本文件解析为DataFrame,使得一行被认为是一行。但是当我按行数分割行分隔列时,它会无限期地挂起。我已经按照相同的步骤解析其他文件,但没有遇到此问题。
解析文件后的输出:
data
0 VL0002511CA 000000000682414100000000000...
1 VL0002511ZZ 000000000682414100000000000...
2 VL0002512 PRE1985000000000682414100000000000...
3 VL0002521CA 000000001888990100000000000...
4 VL0002521ZZ 000000001888990100000000000...
5 VL0002522 PRE1985000000001888990100000000000...
6 VL0002531CA 000000001223831100000000000...
7 VL0002531ZZ 000000001223831100000000000...
8 VL0002532 PRE1985000000001223831100000000000...
9 VL0007871CA 000000001463787100000000000...
10 VL0007871ZZ 000000001463787100000000000...
11 VL0007872 PRE1985000000001463787100000000000...
下面给出了挂起的代码:(在下面的代码中,我试图对数据数据帧进行切片并将它们放在不同的列中。)
df['COLA'] = df.data.str[0:3]
df['COLB'] = df.data.str[3:9]
df['COLC'] = df.data.str[9:10]
df['COLD'] = df.data.str[10:12]
df['COLE'] = df.data.str[12:15]
df['COLF'] = df.data.str[15:17]
df['COLG'] = df.data.str[17:19]
df['COLH'] = df.data.str[19:21]
df['COLI'] = df.data.str[21:23]
df['COLJ'] = df.data.str[23:38]
df['COLK'] = df.data.str[38:43]
df['COLL'] = df.data.str[43:51]
df['COLM'] = df.data.str[51:56]
df['COLN'] = df.data.str[56:57]
df['COLO'] = df.data.str[57:64]
df= df.drop('data', axis=1)
我不确定执行时为什么会挂起。任何人都可以帮忙吗?