我正在加载数据,然后,我试图将df列重命名为小写:
journalist_data = pd.read_csv( cur_dir + 'fandango_score_comparison.csv')
journalist_data_clean = journalist_data.loc[:,['FILM','Fandango_Stars','Fandango_Ratingvalue','Fandango_votes','Fandango_Difference']]
journalist_data_clean_columns = journalist_data_clean.columns.str.lower()
journalist_data_clean.rename(index = str, columns = journalist_data_clean_columns,inplace= True)
但是我有这个问题:
Traceback (most recent call last):
File "C:/ML/DataQuest/Statistics/Fandango project/Investigating Fandango Movie Ratings.py", line 40, in <module>
journalist_data_clean.rename(index = str, columns = journalist_data_clean_columns,inplace= True)
TypeError: 'Index' object is not callable
df的描述:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 146 entries, 0 to 145
Data columns (total 5 columns):
FILM 146 non-null object
Fandango_Stars 146 non-null float64
Fandango_Ratingvalue 146 non-null float64
Fandango_votes 146 non-null int64
Fandango_Difference 146 non-null float64
dtypes: float64(3), int64(1), object(1)
答案 0 :(得分:1)
我仅举一个关于"Lower Case Column Names In Pandas Dataframe"
的示例,希望对您有所帮助...
>>> df
NAME REPORTS YEAR <-- all column names are in upper-case
Cochice Jason 4 2012
Pima Molly 24 2012
Santa Cruz Tina 31 2013
Maricopa Jake 2 2014
Yuma Amy 3 2014
>>> df.columns = map(str.lower, df.columns)
>>> df
name reports year
Cochice Jason 4 2012
Pima Molly 24 2012
Santa Cruz Tina 31 2013
Maricopa Jake 2 2014
Yuma Amy 3 2014
df.columns = df.columns.str.lower()