I have scripts like below:
df['quarter'] = pd.PeriodIndex(df.creation_datetime, freq='Q')
df['quarter']
looks like 2021Q3
in format. I hope to get the unique values of date time and store them into a list. How to achieve something like that? I check the PeriodArray documentation but find no clue.
time_seq = df.quarter.unique().values.to_list()
This just gave me errors like:
AttributeError: 'PeriodArray' object has no attribute 'to_list'
CodePudding user response:
I solved this problem by:
df.quarter = df.quarter.astype(str)
time_quarter = list(df.quarter.unique())
It works!