‘DataFrame’ 对象没有 ‘column’ 属性

huangapple go评论72阅读模式
英文:

'DataFrame' object has no attribute 'column'

问题

我试图检索一个DataFrame的列名,全部都是小写,但是出现了以下的属性错误:'DataFrame'对象没有'column'属性

import pandas as pd

df = pd.read_csv('C:/dataset.csv')

col_names = df.columns.str.lower()
print(col_names)

为什么会出现这个错误,如何修复它?

英文:

I'm trying to retrieve the column names of a dataframe, all in lower case, but that's giving me the following Attribute Error: 'DataFrame' object has no attribute 'column'.

import pandas as pd

df = pd.read_csv('C:/dataset.csv')

col_names=df.column.values.lower()
print(col_names)  

Why is this error showing up & how do I fix it?

答案1

得分: 1

IIUC, 将 "column" 替换为 "columns" 并使用 str.lower 访问器:

col_names = df.columns.str.lower().tolist()
英文:

IIUC, replace "column" by "columns" and use the str.lower accessor:

col_names = df.columns.str.lower().tolist()

huangapple
  • 本文由 发表于 2023年1月9日 13:47:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053578.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定