gpt4 book ai didi

python - pandas系列我要获取今天的数据

转载 作者:行者123 更新时间:2023-12-04 10:32:41 24 4
gpt4 key购买 nike

使用pandas.series 我想获取今天的数据
数据

a=  [{"content": 1, "time": 1577870427}, {"content": 4, "time": 1577870427},
{"content": 2, "time": 1577956827},
{"content": 3, "time": 1580548827}, {"content": 5, "time": 1580635227},
{"content": 6, "time": 1583054427}, {"content": 7, "time": 1582275530}]

最终数据
# today data
[{"content": 6, "time": 1583054427}, {"content": 7, "time": 1582275530}]

我的 cdo
index = pd.to_datetime([i['time'] for i in a], unit='s')
df = pd.Series(a,index)
get today data

最佳答案

这将是我的方法:

import datetime as dt
import pandas as pd

df = pd.DataFrame(a)

# Get a new column with the date.
df['date'] = pd.to_datetime(df['time'], unit='s').dt.date

# Subset df with today's rows.
df[df['date'] == pd.to_datetime(dt.datetime.utcnow().date())]

返回 df :
content time        date
7 1582275530 2020-02-21

关于python - pandas系列我要获取今天的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60335203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com