2024-10-01 19:34:22 发布
网友
我有两个带timeseriesIndex的数据帧,df1,df2。在
df2的索引是df1.index的子集。 如何从df1中提取同样包含在df2中的索引日期,以便对这些日期运行分析。在
取他们指数的交点。在
In [1]: import pandas as pd In [2]: index1 = pd.DatetimeIndex(start='2000-1-1', freq='1T', periods=1000000) In [3]: index2 = pd.DatetimeIndex(start='2000-1-1', freq='1D', periods=1000) In [4]: index1 Out[4]: [2000-01-01 00:00:00, ..., 2001-11-25 10:39:00] Length: 1000000, Freq: T, Timezone: None In [5]: index2 Out[5]: [2000-01-01 00:00:00, ..., 2002-09-26 00:00:00] Length: 1000, Freq: D, Timezone: None In [6]: index1 & index2 Out[6]: [2000-01-01 00:00:00, ..., 2001-11-25 00:00:00] Length: 695, Freq: D, Timezone: None
对于您的情况,请执行以下操作:
然后取前面定义的交点。 稍后,您可能希望执行以下操作以获得df在交叉点处的索引。在
df
df1_intersection =df1.ix[index1 & index2]
取他们指数的交点。在
对于您的情况,请执行以下操作:
^{pr2}$然后取前面定义的交点。 稍后,您可能希望执行以下操作以获得
df
在交叉点处的索引。在相关问题 更多 >
编程相关推荐