简体   繁体   中英

Pandas dataframe column with title 'name'

I have multiple dataframes which I join based on a common column. The code looks like this:

df=reduce(lambda x,y:pd.merge(x,y,on='name'),[total,eliminated, actionable, bug])

Afterwards, I intend to rename the column name . But name is not anymore in the column list. When I print the df , the name column shows but I don't know how to work with that merged column anymore, like renaming.

If I print type(df), df.columns, df , it shows:

(pandas.core.frame.DataFrame,
 Index(['total', 'e', 'a', 'b'], dtype='object'),
                        total      e      a      b
 name                                             
 !CHAOS Control System    282  80.14  39.01   1.42
 Chromium EC              306  93.46  29.74  17.65
 Firefox                 5448  77.22  49.72  12.43

What happended to the name column and how can I rename it afterwards?

It looks like you set 'name' as the index. Try this:

df = df.reset_index()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM