我希望从 Pandas 中选择自定义行和自定义列。
我找到了所需行的索引,它们是。
indices_rows = [224, 290, 390, 130, 262, 338]
以及我希望在我的 DataFrame 中拥有的第一列的索引和最后一列的索引。
index_first = 26
、index_last = 56229
当我想用
提取所需的DataDrame时new_df = data_raw.iloc[[indices_rows],index:index_last]
出现错误:ValueError: Buffer has the wrong number of dimensions (expected 1, got 2)
我不知道为什么。因为它们分开工作。
答案 0 :(得分:1)
移除[]
周围的indices_rows
:
new_df = data_raw.iloc[indices_rows,index:index_last]
因为:
new_df = data_raw.iloc[[indices_rows],index:index_last]
是:
new_df = data_raw.iloc[[[224, 290, 390, 130, 262, 338]],index:index_last]
并且需要:
new_df = data_raw.iloc[[224, 290, 390, 130, 262, 338],index:index_last]