【问题标题】:Autoincrementing option for Pandas DataFrame indexPandas DataFrame 索引的自动递增选项
【发布时间】:2013-01-24 13:00:22
【问题描述】:

有没有办法在添加新行时设置自动增加 pandas.DataFrame 索引的选项,或者定义一个函数来管理新索引的创建?

【问题讨论】:

    标签: python indexing append row pandas


    【解决方案1】:

    append-ing时可以设置ignore_index=True

    In [1]: df = pd.DataFrame([[1,2],[3,4]])
    
    In [2]: row = pd.Series([5,6])
    
    In [3]: df.append(row, ignore_index=True)
    Out[3]: 
       0  1
    0  1  2
    1  3  4
    2  5  6
    

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 1970-01-01
      • 2018-07-03
      • 2020-01-21
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 2019-04-13
      • 2018-08-13
      相关资源
      最近更新 更多