Pandas和努比不会读整个fi

2024-10-02 20:37:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是panda.read\表格用于将表格文件收集到矩阵中。但是,panada处理前4772行没有任何问题,然后跳转错误如下:

return self._getitem_column(key)
  File "C:\Users\YOUJIA LI\PycharmProjects\untitled1\venv\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column
    return self._get_item_cache(key)
  File "C:\Users\YOUJIA LI\PycharmProjects\untitled1\venv\lib\site-packages\pandas\core\generic.py", line 2487, in _get_item_cache
    res = cache.get(item)
TypeError: unhashable type: 'slice'

下面是我用来处理数据的代码:

 from get_line_number import get_line_number
import numpy as np
import pandas as pd

#import file in python
phrase = "STARTS"
file_name = "C:\\Users\\YOUJIA LI\\Desktop\\program\\java\\LAYER.PLT" #(change path )

#find where the file starts
linenumber = get_line_number(phrase,file_name)
with open(file_name) as myfile:
    lineskip = myfile.readlines()[int(linenumber):]

#create a temp. file to store the numerical data
file = open("token.txt",'w')
with open(file_name) as myfile:
    for _ in range(linenumber):
        next(myfile)
    for line in myfile:
        values = line.split()
        # get ride of string leave num along
        values1 = str(values).replace("[","")
        values1 = values1.replace("]","")
        values1 = values1.replace("'","")

        file.write(values1 +'\n')
myfile.close()
matrix = pd.read_table('token.txt', sep=',',header=None,error_bad_lines=False)
print(matrix)

的屏幕截图令牌.txt具体如下: enter image description here


Tags: nameinimportcachepandasgetasline