假设我有一个稀疏的DataFrame
,我想要.fillna(method='ffill')
,,但只能访问具有相同日期的行?
例如,如果df
有行:
2017-01-01 12:00 0.6
2017-01-01 13:00 NaN
2017-01-02 12:00 NaN
2017-01-02 13:00 0.8
然后我想填写产生:
2017-01-01 12:00 0.6
2017-01-01 13:00 0.6
2017-01-02 12:00 NaN
2017-01-02 13:00 0.8
以下是一些代码,用于创建用于演示的稀疏每小时DataFrame:
df = pd.DataFrame(np.random.rand(76), columns=list('X'), index=pd.date_range('2016-01-01', freq='H', periods=76))
df.loc[df['X'] < 0.6, 'X'] = np.nan
答案 0 :(得分:6)
当天执行<html>
<head>
<script type="text/javascript" src="content.js"></script>
</head>
<body>
<p>Turn off <span>class, "class"</span></p>
<button type="button">Turn off</button>
</body>
</html>
,然后致电groupby
:
ffill