I wish to flip the order of characters within the ‘date’ column using Python
Data
id type date
aa hi 2022 Q1
aa hi 2022 Q2
Desired
id type date
aa hi Q1 2022
aa hi Q2 2022
Doing
I believe I can separate and then reverse them?
a = df.split()
Any suggestion is helpful
>Solution :
Indeed, I would do it with list comprehension:
df = pd.DataFrame({'date':['2022 Q1','2022 Q2']})
df['date'] = [' '.join(x.split()[::-1]) for x in df['date']]
Using print(df['date']) Outputs:
0 Q1 2022
1 Q2 2022