【问题标题】:how to slice a dataframe from the end to the beginning?如何从末尾到开头切片数据帧?
【发布时间】:2016-11-30 01:11:02
【问题描述】:

我正在像这样切片数据框:

for i in xrange(0,len(df),100000):
    print("slice %d!!!!" % i)
    slice= df.iloc[i:(i+100000)]

我现在想得到 100k 切片 从 df 的末尾到开头(不必对我的数据框进行排序)。

我该怎么做?

谢谢!

【问题讨论】:

    标签: python pandas indexing dataframe slice


    【解决方案1】:

    只需使用tail:

    df.tail(100000)
    

    【讨论】:

      【解决方案2】:

      iloc 的另一个解决方案:

      df.iloc[-100000:]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-05
        • 2010-10-11
        • 1970-01-01
        • 2016-06-05
        • 1970-01-01
        相关资源
        最近更新 更多