【问题标题】:Indexing in python dataframe using iloc to select all columns except the first column使用 iloc 在 python 数据框中建立索引以选择除第一列之外的所有列
【发布时间】:2020-12-29 13:51:27
【问题描述】:

我正在尝试在 python 中选择 pandas 数据框中的所有列,但使用 iloc 的第一列除外。

我可以使用代码选择除最后一列之外的所有列

Pre_Processed.iloc[:,0:-1]

有人可以帮我解决这个问题吗?

【问题讨论】:

  • Pre_Processed.iloc[:, 1:] ... google indexing in python .... 你的索引就像-iterable[start:end:step]
  • 也叫“切片”。试试this answer

标签: python dataframe indexing multiple-columns


【解决方案1】:

试试这个

Pre_Processed.iloc[:,1:]

带有可迭代的索引的工作方式类似于--iterable[start:end:stride]

了解更多关于 stride-https://www.digitalocean.com/community/tutorials/how-to-index-and-slice-strings-in-python-3#:~:text=The%20third%20parameter %20指定%20the,two%20index%20numbers%20is%20retrived。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 2017-11-13
    • 2020-12-17
    • 1970-01-01
    • 2018-12-16
    • 2019-01-17
    • 1970-01-01
    相关资源
    最近更新 更多