【问题标题】:Pandas: Return a new Dataframe with specific non continuous column selection [duplicate]熊猫:返回具有特定非连续列选择的新数据框[重复]
【发布时间】:2016-09-17 16:17:18
【问题描述】:

我有一个包含 85 列和大约 10.000 行的数据框。
第一列是Shrt_Desc,最后一列是Refuse_Pct
我想要的新数据框必须有Shrt_Desc,然后留下一些列,然后在系列中包含Fiber_TD_(g)Refuse_Pct
我用:

dfi_3 = food_info.loc[:, ['Shrt_Desc', 'Fiber_TD_(g)':'Refuse_Pct']] 

但它给出了语法错误。 有什么想法可以实现吗?
谢谢。

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    借用this answer的主要思想:

    pd.concat([food_info['Shrt_Desc'], food_info.ix[:, 'Fiber_TD_(g)':]], axis=1) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 2018-03-04
      • 1970-01-01
      • 2015-03-29
      • 2021-07-15
      • 2020-05-09
      • 1970-01-01
      相关资源
      最近更新 更多