Home > Software design >  how to convert the Index colum to normal column.?1st 2colm are index & I applied df_agg.index & I am
how to convert the Index colum to normal column.?1st 2colm are index & I applied df_agg.index & I am

Time:02-02

                         Txn_Date                       Expected out

Acc_No new_Txn_date

121      1/1/2011       (121, 2011-04-01 00:00:00)      2011-04-01
         2/1/2011       (121, 2011-04-01 00:00:00)      2011-04-01
         4/1/2011       (121, 2011-04-01 00:00:00)      2011-04-01

123      10/1/2011      (123, 2011-10-01 00:00:00)      2011-10-01 
         20/1/2011      (123, 2011-20-01 00:00:00)      2011-20-01
         04/1/2011      (123, 2011-04-01 00:00:00)      2011-04-01

I am expecting only dates in Txn_date?how to do it, I just applied df.index on the data frame but it's showing both indexes combined but I wanted only the date in my txn_date column

CodePudding user response:

Use

df = df.reset_index()

Example:

df = pd.DataFrame({'a': [1,2,3]})
>>> 
Out[23]: 
   a
0  1
1  2
2  3
df.reset_index()
>>>
   index  a
0      0  1
1      1  2
2      2  3

CodePudding user response:

Try the follwing.

index, df['Txn_Date'] = zip(*df['Txn_Date'])

where df is your dataframe df_agg as shown in your question.

But please check that 'Txn Date' must contain 2 element tuple throughout the dataframe.

  •  Tags:  
  • Related