Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dataframe reindex on a column

Tags:

python

pandas

This is my dataframe

      ticker        date   dateValue
549      RCG  2015-01-02    10
692      RCG  2015-01-05    8

I want to have this have reindex

foo =  foo.reindex(index=['2015-01-01', '2015-01-02'])

ticker        date   dateValue
RCG  2015-01-01    N/A
RCG  2015-01-02    10

Instead I get

       ticker date   dateValue
2015-01-01    NaN  NaN          NaN
2015-01-02    NaN  NaN          NaN
like image 206
kay00 Avatar asked Aug 07 '15 20:08

kay00


1 Answers

You can simply set the index:

df = pd.DataFrame({'ticker': ['RCG','RCG'], 'date': ['2015-01-02','2015-01-05'], 'dateValue':[10,8]}, index=[549, 692])
df.set_index('date', inplace=True)
print(df)

            dateValue ticker
date                        
2015-01-02         10    RCG
2015-01-05          8    RCG

Is it the expected result ?

like image 134
Romain Avatar answered Sep 29 '22 07:09

Romain