'how to convert the Index colum to normal column.?1st 2colm are index & I applied df_agg.index & I am getting column where I need only Date in Txn_Date
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
Solution 1:[1]
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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eyal Asulin |
| Solution 2 | helloWORLD |
