无法使用熊猫中的跳过行跳过行

时间:2019-12-08 13:59:17

标签: python-3.x pandas dataframe

伙计们,我刚才在研究熊猫,我导入了excel数据集,并试图通过跳过前四行来选择标题,但它不起作用,伙计们可以帮助我做到这一点

这是我的代码

import pandas as pd
df = pd.read_excel("Practical example Descriptive statistics_exercise.xlsx", skiprow = 4)
df

这是我所做的,但是我想将标头添加到标有标题的

1 个答案:

答案 0 :(得分:1)

我认为您需要指定所有要在列表中跳过的行:

df = pd.read_excel("Practical example Descriptive statistics_exercise.xlsx",
                   skiprows = [0,1,2,3])

或指定哪一行是标题:

df = pd.read_excel("Practical example Descriptive statistics_exercise.xlsx", header= 4)

Python从0开始计数,因此对于排除第一行使用0,对于第五行标头使用4