pandas df.timestamp.dt.date.unique()似乎不起作用

lb3vh1jj  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(106)

下面是 Dataframe :

timestamp    open    high     low   close   volume
0     2023-01-03 09:30:00  3.5000  3.5800  3.5000  3.5300   1595.0
1     2023-01-03 09:35:00  3.5800  3.5800  3.5800  3.5800    102.0
2     2023-01-03 09:40:00  3.5972  3.5972  3.5972  3.5972    103.0
3     2023-01-03 09:50:00  3.5500  3.5700  3.5000  3.5200   3032.0
4     2023-01-03 09:55:00  3.4100  3.5900  3.4100  3.5900   2205.0
...                   ...     ...     ...     ...     ...      ...
1245  2023-02-21 19:35:00  6.7100  6.7200  6.7100  6.7200    739.0
1246  2023-02-21 19:40:00  6.7200  6.7300  6.7200  6.7300   2243.0
1247  2023-02-21 19:45:00  6.7300  6.7300  6.7000  6.7000   1412.0
1248  2023-02-21 19:50:00  6.7100  6.7400  6.7000  6.7400   4082.0
1249  2023-02-21 19:55:00  6.7400  6.8500  6.6500  6.7200  23678.0

[1250 rows x 6 columns]

我想提取所有的日期,但是dataframe不允许,我怎么才能唯一提取所有的日期呢?我试过dtdf.timestampdf['timestamp'].timestamp,但是它不是一个属性,我知道dataframe和series的区别,但是现在我绝望了
我尝试使用df.timestamp.dt.date.unique(),但似乎没有任何工作。

q8l4jmvw

q8l4jmvw1#

df["timestamp"]=pd.to_datetime(df["timestamp"])

这会将时间戳转换为datetime64格式

df["timestamp"].dt.date.unique().astype("str")

this在timestamp列中给出所有唯一值,并将它们作为字符串返回。dt.date将timestamp格式化为没有时间的仅日期格式。

相关问题