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
1 Answer
Reset to default 1Maybe 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
版权声明:本文标题:python - Pandas is not reading the column name in spite of it being there - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741612935a2388364.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
title
seems to be an index not a data column. You can usedf = df.reset_index()
to revert to the default numerical index and restore the column. – user19077881 Commented Feb 12 at 11:08