【问题标题】:How to use an integer list to find rows in pd.DataFrame with non-integer indices如何使用整数列表在 pd.DataFrame 中查找具有非整数索引的行
【发布时间】:2019-09-29 15:43:03
【问题描述】:

我怎样才能做到这一点?

import pandas as pd

L = [1,3,5]
df = pd.DataFrame([1,2,3,4,5,6,7], index=[0.1,0.2,0.3,0.4,0.5,0.6,0.7])

print(df[0])
print(df[0].loc(L))

我想要这种输出格式:

0.2    2
0.4    4
0.6    6

【问题讨论】:

  • 您确定您提供的输出正确吗?对于给定的输出整数应该是列表 L = [1,4,6]

标签: python-3.x pandas indexing


【解决方案1】:

我认为是.iloc

df.iloc[L]
Out[477]: 
     0
0.2  2
0.4  4
0.6  6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-12
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2017-02-21
    • 2022-01-01
    • 1970-01-01
    相关资源
    最近更新 更多