【发布时间】:2019-09-24 07:04:56
【问题描述】:
我有一个 Pandas DataFrame(从 excel 文件创建),我想在其中查看一行,忽略 nan 值,并获取剩余元素的位置。所以我在做:
lines = df.iloc[16, :].dropna()
print(lines)
产量:
2 10
6 11
10 12
14 13
18 14
第一列是 Pandas 为我的 excel 中的每一行提供的自动索引。我想要列出这些索引,position = [2, 6, 10, 14, 18]。
如何提取这些索引?我尝试使用lines.tolist(),但它只获取没有位置/索引的值。
【问题讨论】:
-
lines.index.tolist() -
df.iloc[16, :].dropna().index.tolist()