代码之家  ›  专栏  ›  技术社区  ›  Florent

如何重用从iterrows接收的索引来创建另一个数据帧?

  •  0
  • Florent  · 技术社区  · 3 年前

    我遍历一个数据帧的行,并尝试使用从iterrows收到的相同索引重新创建另一个数据帧。我的问题是,该索引不被接受,我该怎么做?

    for idx, row in df.iterrows:
        w = get_series(row)
        print(w)
        print(idx)
        df = pd.DataFrame([w], index=idx)
    

    返回:

    PPP     4.271205e-14
    OOO     3.463379e-01
    BBB     0.000000e+00
    AAA     1.900294e-02
    dtype: float64
    2020-01-09 00:00:00+00:00
    
    TypeError: Index(...) must be called with a collection of some kind, Timestamp('2020-01-09 00:00:00+0000', tz='UTC', freq='H') was passed 
    
    0 回复  |  直到 3 年前