这是我的数据框。
相反,我得到了
ticker date dateValue
549 RCG 2015-01-02 10
692 RCG 2015-01-05 8
我希望进行重新索引
foo = foo.reindex(index=['2015-01-01', '2015-01-02'])
ticker date dateValue
RCG 2015-01-01 N/A
RCG 2015-01-02 10
相反,我得到了
ticker date dateValue
2015-01-01 NaN NaN NaN
2015-01-02 NaN NaN NaN
reindex
时也遇到了同样的问题,为什么reindex
返回带有 NaN 值的列? - Arnav Daspandas.DataFrame.reindex
和pandas.DataFrame.set_index
的文档。它们有完全不同的应用场景。reindex
更类似于.loc
,但允许使用以前不存在的索引。 - Michael Delgado