简体   繁体   中英

rename a non existing column in dataFrame

I have a dataframe dfWaits like this

waitEvent   snapDate        gc cr block 3-way   gc current block 3-way  log file sync
instance                
AAA         2015-Jul-01     NaN                     2                       9
BBB         2015-Jul-01     NaN                     2                       8
AAA         2015-Jul-03     NaN                     1                       9
BBB         2015-Jul-03     1                       2                       8
AAA         2015-Jun-29     NaN                     2                       8
BBB         2015-Jun-29     NaN                     2                       8

dfWaits.columns

Index(['snapDate', 'gc cr block 3-way', 'gc current block 3-way',
       'log file sync'],
      dtype='object', name='waitEvent')

dfWaits.index
Index(['AAA', 'BBB', 'AAA', 'BBB', 'AAA',
       'BBB'],
      dtype='object', name='instance')

I would want to rename the column waitEvent as instance.

I would also want to draw a matplot lib chart with snapdate on x-axis and gc cr block 3-way,gc current block 3-way and log file sync on the y axis.

I tried this dfWaits.loc['AAA'].plot()

but this gives me instance against x-axis instead of the snapDate.

To get rid of your waitEvent label (actually a label on your columns), set

df.columns.name=None

For your plot set the snapDate as your index and then call plot() on the columns you want:

df.index = df.snapDate
df.iloc[:,[2,3,4]].plot()

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