我正在讀取類似於以下內容的.txt文件中的數據,並且我在每個括號中提取第三項,代碼是底端。系列對象沒有拆分屬性 - 從文本文件中讀取數據
隨着線data = data.iloc[0, ::4]
,我從每4個數據點中刪除3(我認爲)。
但是,現在我試圖保留每個數據點。所以當我刪除線時, data = data.iloc[0, ::4]
,我收到以下錯誤:
"'Series' object has no attribute 'split'", 'occurred at index 0'
我不明白爲什麼刪除該行給我,我收到錯誤。總之,我想從每個支架中提取每三個項目,並將其存儲在pandas
DataFrame
中。但是,當我嘗試刪除行data = data.iloc[0, ::4]
時,出現錯誤(如上所示)。
感謝您的支持!
data = pd.read_csv("C:\\Users\\Desktop\\data_test9.txt", sep="\[|\]\[|\]",engine = 'python', header = None)
data = data.iloc[0, ::4]
data = data.astype(str).apply(lambda x: x.split(',')[-1]).astype(float)
data.pop(0)
xar = range(len(data)
yar = pd.DataFrame(data)
數據的片:
[0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625]
編輯1: 我的數據被保存如下:
while True:
delay(DELAY_INTERVAL)
file = open("C:\\Users\\Desktop\\demo3.txt", "a")
file.writelines(str(convert(readField())))
file.flush()
file.close()
基本上,您應該重新考慮您保存數據的格式,它看起來像一個'print'轉儲。使用'csv'格式,或其他。 –
因此,正如我懷疑你基本上將某些數據結構的'str'表示轉儲到文本文件。 *不要這樣做*。您將不得不按照您嘗試的方式將數據解析回數據結構。只需使用接受和支持的格式,如'csv'。那麼你不必編寫解析邏輯。 –
我正在考慮使用'csvwriter'。這是一個好主意嗎? – Gary