【发布时间】:2022-12-09 14:47:30
【问题描述】:
我是大熊猫的新手。我正在处理的文件非常大,我只想从 9 列中读取几行。但是,当我运行代码时,它只显示 9 列中的 3 列。我不知道为什么。
columns = [0, 1, 2, 3, 4, 5, 10, 12, 17]
header_names = ['Incident Number', 'Incident Type', 'Report Date', 'Nearest Populated Center',
'Province', 'Company', 'Substance', 'Significant', 'What Happened category']
p_line = pd.read_csv(r"pipeline_data.csv",
skiprows=1,
nrows=5,
usecols=columns,
names=header_names,
index_col=0)
这是输出... 另外,为什么不打印事件编号?
Incident Type ... What Happened category
Incident Number ...
INC2007-097 Release of Substance ... Corrosion and Cracking
INC2008-001 Release of Substance ... Corrosion and Cracking
INC2008-004 Release of Substance ... Equipment Failure
INC2008-008 Release of Substance ... Defect and Deterioration
INC2008-009 Release of Substance, Adverse Environmental Ef... ... Equipment Failure
[5 rows x 8 columns]
然后我补充说
pd.set_option('display.max_columns', None)
但是输出随后被分解了....
Incident Type \
Incident Number
INC2007-097 Release of Substance
INC2008-001 Release of Substance
INC2008-004 Release of Substance
INC2008-008 Release of Substance
INC2008-009 Release of Substance, Adverse Environmental Ef...
Report Date Nearest Populated Center Province \
Incident Number
INC2007-097 01/02/2008 Grande Prairie Alberta
INC2008-001 01/02/2008 Cromer Manitoba
INC2008-004 01/23/2008 Cromer Manitoba
INC2008-008 01/29/2008 Fort Nelson British Columbia
INC2008-009 01/29/2008 Taylor British Columbia
Company \
Incident Number
INC2007-097 Alliance Pipeline Ltd.
INC2008-001 Enbridge Pipelines Inc.
INC2008-004 Enbridge Pipelines Inc.
INC2008-008 Westcoast Energy Inc., carrying on business as...
INC2008-009 Westcoast Energy Inc., carrying on business as...
Substance Significant \
Incident Number
INC2007-097 Natural Gas - Sweet No
INC2008-001 Crude Oil - Sweet No
INC2008-004 Crude Oil - Sweet No
INC2008-008 Natural Gas - Sweet No
INC2008-009 Potassium Hydroxide (caustic solution) Yes
What Happened category
Incident Number
INC2007-097 Corrosion and Cracking
INC2008-001 Corrosion and Cracking
INC2008-004 Equipment Failure
INC2008-008 Defect and Deterioration
INC2008-009 Equipment Failure
我只想要一张长表中的所有信息,而不是一些奇怪的破碎表
【问题讨论】: