我有一个像这样的Pandas DataFrame:
import numpy as np
import pandas as pd
np.random.seed(1234)
midx = pd.MultiIndex.from_product([['a', 'b', 'c'], pd.date_range('20130101', periods=6)], names=['letter', 'date'])
df = pd.DataFrame(np.random.randn(len(midx), 1), index=midx)
Run Code Online (Sandbox Code Playgroud)
该数据框如下所示:
0
letter date
a 2013-01-01 0.471435
2013-01-02 -1.190976
2013-01-03 1.432707
2013-01-04 -0.312652
2013-01-05 -0.720589
2013-01-06 0.887163
b 2013-01-01 0.859588
2013-01-02 -0.636524
2013-01-03 0.015696
2013-01-04 -2.242685
2013-01-05 1.150036
2013-01-06 0.991946
c 2013-01-01 0.953324
2013-01-02 -2.021255
2013-01-03 -0.334077
2013-01-04 0.002118
2013-01-05 0.405453
2013-01-06 0.289092
Run Code Online (Sandbox Code Playgroud)
我想要做的就是保持基于一个条件的所有行日期取决于该信.例如,