Python中文
首页
教程
问答
标签
搜索
登录
注册
python pandas通过另一系列、多个列来过滤数据帧
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>在获得了一系列交货数量最高的天数之后,如何过滤掉这些天的原始数据帧?考虑到这两个因素:</p> <pre><code>most_liquid_contracts.head(20) Out[32]: 2007-04-26 706 2007-04-27 706 2007-04-29 706 2007-04-30 706 2007-05-01 706 2007-05-02 706 2007-05-03 706 2007-05-04 706 2007-05-06 706 2007-05-07 706 2007-05-08 706 2007-05-09 706 2007-05-10 706 2007-05-11 706 2007-05-13 706 2007-05-14 706 2007-05-15 706 2007-05-16 706 2007-05-17 706 2007-05-18 706 dtype: int64 df.head(20).to_string Out[40]: <bound method DataFrame.to_string of delivery volume 2007-04-27 11:55:00+01:00 705 1 2007-04-27 13:46:00+01:00 705 1 2007-04-27 14:15:00+01:00 705 1 2007-04-27 14:33:00+01:00 705 1 2007-04-27 14:35:00+01:00 705 1 2007-04-27 17:05:00+01:00 705 16 2007-04-27 17:07:00+01:00 705 1 2007-04-27 17:12:00+01:00 705 1 2007-04-27 17:46:00+01:00 705 1 2007-04-27 18:25:00+01:00 705 2 2007-04-26 23:00:00+01:00 706 10 2007-04-26 23:01:00+01:00 706 12 2007-04-26 23:02:00+01:00 706 1 2007-04-26 23:05:00+01:00 706 21 2007-04-26 23:06:00+01:00 706 10 2007-04-26 23:07:00+01:00 706 19 2007-04-26 23:08:00+01:00 706 1 2007-04-26 23:13:00+01:00 706 10 2007-04-26 23:14:00+01:00 706 62 2007-04-26 23:15:00+01:00 706 3> </code></pre> <p>我试过:</p> ^{pr2}$ <p>或者我需要合并吗?它看起来不那么优雅,我也不确定。。我试过:</p> <pre><code># ATTEMPT 1 most_liquid_contracts.index = pd.to_datetime(most_liquid_contracts.index, unit='d') df['days'] = pd.to_datetime(df.index.date, unit='d') mlc = most_liquid_contracts.to_frame(name='delivery') mlc['days'] = mlc.index.date data = pd.merge(mlc, df, on=['delivery', 'days'], left_index=True) # ATTEMPT 2 liquid = pd.merge(mlc, df, on='delivery', how='inner', left_index=True) # this gets me closer (ie. retains granularity), but somehow seems to be an outer join? it includes the union but not the intersection. this should be a subset of df, but instead has about x50 the rows, at around 195B. df originally has 4B </code></pre> <p>但我似乎无法保留原始“df”中所需的分钟级粒度。基本上,我只需要“df”来表示最具流动性的合同(它来自于最具流动性的合同系列;例如,4月27日只包括“706”标签的合同,4月29日只包括“706”标签的合同)。第二个df则正好相反:所有其他合约的df(即流动性最高的合约)。在</p> <p>更新:了解更多信息-- <img src="https://i.stack.imgur.com/5xUAf.png" alt="enter image description here"/></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我假设我对你的理解是正确的,最流动的合同系列是包含N个整数N的最大交货量的系列。你想过滤df,只包括交货数足够高的天数,以便列在清单上。因此,你不能简单地把所有的东西都去掉。在</p> <pre><code>threshold = min(most_liquid_contracts) filtered = df[df['delivery'] >= threshold] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
10 回答
如何在python中从数据帧列表中删除引号
8 回答
如何在python中从数据帧创建列表
5 回答
如何在Python中从数据帧创建嵌套的JSON
4 回答
如何在Python中从数据帧显示wordcloud
3 回答
如何在Python中从数据帧的时间戳中删除字符
4 回答
如何在Python中从数据帧绘制简单绘图?
4 回答
如何在python中从数据帧行提取具有特定长度的范围?
5 回答
如何在python中从数据帧设置dict中的值
9 回答
如何在Python中从数据库中获得一个结果
10 回答
如何在python中从数据框中绘制分类条形图
7 回答
如何在Python中从数据框中选择特定细节?
2 回答
如何在python中从数据集中删除unicode
2 回答
如何在python中从数据集中删除某些数值?
3 回答
如何在python中从数据集中选择行
5 回答
如何在Python中从数组中删除元素
7 回答
如何在python中从数组中删除单个倒逗号?
3 回答
如何在python中从数组中删除对象?
6 回答
如何在python中从数组中删除引号
8 回答
如何在python中从数组中删除所有最小值
4 回答