【问题标题】:Python Pandas Error printing the column headingsPython Pandas 打印列标题时出错
【发布时间】:2019-07-30 02:11:56
【问题描述】:

我正在尝试使用 pandas 将包含数据的 excel 工作表导入 python,但出现 pandas 解析器错误,其中预期字段为 10,但看到的是 11。

当我指定列时,它会打印所有数据及其列标题,但会将列标题加倍作为一行数据。

import pandas as pd
columns=['bookID','title','authors','average_rating','isbn','isbn13','language_code','# num_pages','ratings_count','text_reviews_count']

df = pd.read_csv (r'path of the csv file', name=columns)
print(df)

显示列标题

bookID | title | authors | average_rating | isbn |isbn13 | language_code | # num_pages | ratings_count | text_reviews_count

然后再次添加列标题作为第一行数据

0  | bookID | title | authors | average_rating | isbn |isbn13 | language_code | # num_pages | ratings_count | text_reviews_count

【问题讨论】:

    标签: python pandas tokenize


    【解决方案1】:

    我想您可以简单地使用header='infer',因为您在读取的 CSV 文件中已经有了列标题。

    df = pd.read_csv (r'path of the csv file',header='infer') 
    

    pandas.read_csv

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-10
      • 2021-10-15
      • 2022-01-26
      • 1970-01-01
      • 2014-09-16
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多