我是熊猫新手。我正在使用的文件非常大,我只想从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
我只想把所有的信息放在一个长表中,而不是一些奇怪的分割表
也许你可以使用这个函数并在新的选项卡中查看你的表
df.to_html('data.html')
您可以使用以下配置选项:
-
pd.options.display.max_columns = None
它设置了当帧打印得很好并且截断的行被省略号取代时显示的最大列数。
-
pd.options.display.max_colwidth = None
设置列的最大宽度。此长度或更长的单元格将使用省略号截断。
-
pd.options.display.width = 1000
您必须对该值进行试验。设置显示的字符数。
其他配置选项在这里解释