2

I started with:

                     DISCH_PRESS  stage
timestamp                              
2017-11-17 07:10:09  6241.483887   14.0
2017-11-17 07:10:12  6353.102051   14.0
2017-11-17 07:10:15  6673.465820   14.0
2017-11-17 07:10:17  7089.970215   14.0
2017-11-17 07:10:20  7449.266113   14.0

I performed the following operation to resample the timestamp after each stage was grouped:

df = df.groupby(['stage']).resample('1S').asfreq()

Now my data looks like this:

                           DISCH_PRESS  stage
stage timestamp                              
1.0   2017-11-18 23:18:20  4728.775879    1.0
      2017-11-18 23:18:21          NaN    NaN
      2017-11-18 23:18:22          NaN    NaN
      2017-11-18 23:18:23  5109.784180    1.0
      2017-11-18 23:18:24          NaN    NaN

I want to remove the stage row index. My data should look like:

                     DISCH_PRESS  stage
timestamp                              
2017-11-18 23:18:20  4728.775879    1.0
2017-11-18 23:18:21          NaN    NaN
2017-11-18 23:18:22          NaN    NaN
2017-11-18 23:18:23  5109.784180    1.0
2017-11-18 23:18:24          NaN    NaN

When I tried searching for solutions I mostly found solutions to multi column indexing, I tried adapting those solutions for my application, see the following inputs and resulting errors:

df.MultiIndex.droplevel(level=0)
AttributeError: 'DataFrame' object has no attribute 'MultiIndex'

df.droplevel(level=0)
AttributeError: 'DataFrame' object has no attribute 'droplevel'

dframe.reset_index()
ValueError: cannot insert timestamp, already exists

df.rows.droplevel()
AttributeError: 'DataFrame' object has no attribute 'row'

Obviously I am using these methods incorrectly. Any help is appreciated.

red79phoenix
  • 91
  • 3
  • 14

0 Answers0