admin管理员组

文章数量:1295117

The column name of the first column ('title') is not read by pandas. In spite of the column name being there, while displaying the list of columns, in the output name of the first column is missing.

print(news.columns) misses the name of first column

The column name of the first column ('title') is not read by pandas. In spite of the column name being there, while displaying the list of columns, in the output name of the first column is missing.

print(news.columns) misses the name of first column

Share edited Feb 25 at 23:58 halfer 20.5k19 gold badges109 silver badges202 bronze badges asked Feb 12 at 9:11 Reetuparna GhoshReetuparna Ghosh 11 silver badge 1
  • 1 title seems to be an index not a data column. You can use df = df.reset_index() to revert to the default numerical index and restore the column. – user19077881 Commented Feb 12 at 11:08
Add a comment  | 

1 Answer 1

Reset to default 1

Maybe your title column is not actually a column but an index trying using this.

print(df.index)

You can define your own columns and skip the headers from csv file

import pandas as pd

column_names = ["title", "text", "subject", "date", "label"]  # Define the expected column names
df = pd.read_csv("your_file.csv", names=column_names, header=0) 

本文标签: pythonPandas is not reading the column name in spite of it being thereStack Overflow