- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个数据框:
DF1:
StartDate Location
2013-01-01 20000002
2013-03-01 20000002
2013-08-01 20000002
2013-01-01 20000003
2013-03-01 20000003
2013-05-01 20000003
2013-01-01 20000043
EmpStartDate Location
2012-12-17 20000002.0
2013-02-25 20000002.0
2013-06-26 20000002.0
2012-09-24 20000003.0
2013-01-07 20000003.0
2013-07-01 20000043.0
StartDate Location Count
2013-01-01 20000002 1
2013-03-01 20000002 2
2013-08-01 20000002 3
2013-01-01 20000003 1
2013-03-01 20000003 2
2013-05-01 20000003 2
2013-01-01 20000043 0
最佳答案
merge_asof
保持left
的大小DataFrame,所以它不能匹配 left
中的同一行到 right
中的多行.
一种简单但可能内存效率低下的计算方法是执行一个大 merge
在 Location
然后计算有多少行 df.EmpStartDate < df.StartDate
df = df1.merge(df2)
(df.assign(Count = df.EmpStartDate < df.StartDate)
.groupby(['StartDate', 'Location'])
.Count.sum()
.astype('int')
.reset_index())
输出:
StartDate Location Count
0 2013-01-01 20000002 1
1 2013-01-01 20000003 1
2 2013-01-01 20000043 0
3 2013-03-01 20000002 2
4 2013-03-01 20000003 2
5 2013-05-01 20000003 2
6 2013-08-01 20000002 3
关于python - 多列上的 Pandas merge_asof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53157280/
我知道以前也有人问过类似的问题。但是,我的问题略有不同。我正在尝试跨多个列获取 merge_asof 的功能。这是数据集: import pandas as pd left = pd.DataFram
我有一个合并的数据框,如下所示: >>> merged_df.dtypes Jurisdiction object AdjustedVolume
我有两个数据框: DF1: StartDate Location 2013-01-01 20000002 2013-03-01 20000002 2013-08-01
我正在尝试按时间合并多个匹配的两个数据帧。我正在查找 timestamp 在 df1 中的 endofweek 之前 7 天或更短时间的 df2 的所有实例。可能有多个记录符合这种情况,我想要所有匹配
我正在尝试使用 pd.merge_asof 合并多个数据帧。 它们都包含 2 个以日期时间作为索引列的列和一个具有 float 值的变量列。它们的索引和时间不平衡,因此我必须对值进行标准化。 Date
嗨,我需要将一些时间序列数据与最近的时间戳对齐,所以我认为 pandas.merge_asof可能是一个很好的候选人。但是,它没有设置 how='outer' 的选项。就像在标准中 merge方法。
我有以下 2 个 DataFrame。 A 具有数据,B 具有数据的权重。 B 具有权重作为索引生效的日期,“level_1”具有与权重相关的实体。 A = pd.DataFrame(index=pd
我尝试使用 merge_asof 加入 2 个数据帧功能。第一个数据框包含一行失败的组件。 >>> import pandas as pd >>> from datetime import datet
我是第一次使用 Azure Data Lake Analytics,我不确定如何像在 python 中使用 pandas 那样合并 2 个数据集。 我正在合并两个具有不同时间戳的数据集,但如果它们在特
我正在处理两个数据集,每个数据集都有不同的关联日期。我想合并它们,但由于日期不完全匹配,我相信 merge_asof() 是最好的方法。 但是,merge_asof() 会发生两件不理想的事情: 数字
我有一个数据集,包括轮类的开始和结束时间,如下所示: schedule = pd.DataFrame({ "start": pd.to_datetime(['2017-01-01 00:59:
代码是: import numpy as np import pandas as pd dateparse = lambda x: pd.datetime.strptime(x,'%d %m %Y %
我发现了这个不错的函数 pandas.merge_asof。来自文档 pandas.merge_asof(left, right, on=None, left_on=None, right_on=No
表 A 有很多列,其中有一个日期列,表 B 有一个日期时间和一个值。两个表中的数据都是零星生成的,没有固定的时间间隔。表 A 很小,表 B 很大。 我需要在 A.datetime 的给定元素 a 的条
当使用 pandas merge_asof 时,如下例所示 import pandas as pd left = pd.DataFrame({'a': [1.1, 5.5, 10.9], 'left_
我有两个数据帧,df1 和 df2 说,它们都是多索引的。 在第一个索引级别,两个数据帧共享相同的键(即 df1.index.get_level_values(0) 和 df2.index.get_l
我想将目标列从一个数据框合并到另一个数据框。合并后的数据框有更多的键,它们很接近,但与原始数据框不完全匹配。请参见下面的示例: 原始数据帧(FDMA) DMA 130506 130510 1305
pandas merge_asof 函数 documentation page给出了一个对我来说效果很好的例子: left = pd.DataFrame({'a': [1, 5, 10], 'left
我刚刚发现了 pandas merge_asof 函数并试图让它工作。 下面是一些重现我所看到的错误的示例代码: d1 = pd.DataFrame.from_dict({'id':[646327.0
pandas.merge_asof 合并两个数据帧,执行左连接,除非它匹配最近的键而不是相等的键。 示例(从 documentation 窃取): >>> quotes
我是一名优秀的程序员,十分优秀!