【发布时间】:2020-08-18 04:40:21
【问题描述】:
我发现这种问题已经被问过很多次了,但我没有像我这样简单的案例:(
我有一个 test.txt 文件
1 2 3
4 5 6
7 8 9
我编写了以下 Python 代码
import pandas as pd
import csv
file_0 = 'test.txt'
a0 = pd.read_csv(file_0, header = None)
#a0_df = pd.DataFrame(a0)
print(a0)
print(a0.iloc[:,1])
它会导致以下错误消息
raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
我想得到2 5 8,哪里出错了?
【问题讨论】:
-
也许它在一列中读取了整个
1 2 3,尝试指定分隔符..
标签: python python-3.x pandas