Issue
I'm trying to convert DatetimeArray
instance arr
to list
.
I've tried arr.to_list()
, which gives:
'DatetimeArray' object has no attribute 'tolist'
The higher level outcome I'm trying to achieve is, I have this df
with a column dt
that are pandas timestamps. I want to get a list (or anything I can iterate over) of the unique df.dt
, and also prepend to that list another timestamp another_dt
.
Solution
Did you try list()
:
dta = pd.arrays.DatetimeArray(pd.DatetimeIndex(['2023-01-01', '2023-01-02']), freq='D')
print(list(dta))
# Output
[Timestamp('2023-01-01 00:00:00'), Timestamp('2023-01-02 00:00:00')]
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.