我的资料
data= [{"content": "11", "title": "刘德华", "info": "2020-01-13", "time": 1578877014},
{"content": "22", "title": "刘德", "info": "2020-01-24", "time": 1579877014},
{"content": "33", "title": "apple", "info": "2020-02-28", "time": 1582877014},
{"content": "55", "title": "app", "info": "2020-02-17", "time": 1581877014},
{"content": "66", "title": "appstore", "info": "2019-06-30", "time": 1561877014},
{"content": "44", "title": "banana", "info": "2020-02-28", "time": 1582876014},
{"content": "aa", "title": "banana", "info": "2020-03-12 eee", "time": 1584000882},
{"content": "bb", "title": "Thursday data", "info": "2018-03-12 vvvv", "time": 1520842482},
{"content": "cc", "title": "banana", "info": "2020-03-14 xxx", "time": 1584154305},
{"content": "cc", "title": "banana", "info": "2019-03-14 aa", "time": 1552531905},
{"content": "cc", "title": "Thursday data", "info": "2020-03-19 data", "time": 1584586305},
{"content": "cc", "title": "Thursday data", "info": "2019-11-07 aaa", "time": 1573095105},
]
我想获取所有星期四的数据,不仅包含今年,我希望数据是
{"content": "bb", "title": "Thursday data", "info": "2018-03-12 bbb", "time": 1520842482},
{"content": "cc", "title": "Thursday data", "info": "2020-03-19 aaa ", "time": 1584586305},
{"content": "cc", "title": "Thursday data", "info": "2019-11-07
aaa", "time": 1573095105},
无法提供想法,谢谢
问题来源:stackoverflow
将Series.str.get
与带有日期时间的Series.eq
和Series.dt.day_name
进行比较:
s = pd.Series(L)
s1 = s[pd.to_datetime(s.str.get('time'), unit='s').dt.day_name() == 'Thursday']
print (s1)
6 {'content': 'aa', 'title': 'banana', 'info': '...
9 {'content': 'cc', 'title': 'banana', 'info': '...
10 {'content': 'cc', 'title': 'Thursday data', 'i...
11 {'content': 'cc', 'title': 'Thursday data', 'i...
dtype: object
细节 :
print (s.str.get('time'))
0 1578877014
1 1579877014
2 1582877014
3 1581877014
4 1561877014
5 1582876014
6 1584000882
7 1520842482
8 1584154305
9 1552531905
10 1584586305
11 1573095105
dtype: int64
print (pd.to_datetime(s.str.get('time'), unit='s'))
0 2020-01-13 00:56:54
1 2020-01-24 14:43:34
2 2020-02-28 08:03:34
3 2020-02-16 18:16:54
4 2019-06-30 06:43:34
5 2020-02-28 07:46:54
6 2020-03-12 08:14:42
7 2018-03-12 08:14:42
8 2020-03-14 02:51:45
9 2019-03-14 02:51:45
10 2020-03-19 02:51:45
11 2019-11-07 02:51:45
dtype: datetime64[ns]
*
print (pd.to_datetime(s.str.get('time'), unit='s').dt.day_name()) 0 Monday 1 Friday 2 Friday 3 Sunday 4 Sunday 5 Friday 6 Thursday 7 Monday 8 Saturday 9 Thursday 10 Thursday 11 Thursday dtype: object
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。