我有一个26列100行的PandasData帧。我想从第25列(称为未命名:24)第50行中提取特定值并将其放入列表中。有没有办法做到这一点?我的列名为Unnamed:0,Unnamed:1,...,Unnamed:25;行只是0到99:
Unnamed 0: ..... Unnamed: 24 Unnamed: 25
0
1
.
.
50 50
.
.
99
和
Numbers = []
我想将此值50附加到第24行第50行的Numbers。
我的数据框是x = xls.parse('excelfile1.xls'),我正在从Excel电子表格中解析数据框
答案 0 :(得分:0)
您可以使用iloc
:
Numbers = []
value = df1.iloc[24,50]
Numbers.append(value)
或者作为更一般的例子:
import pandas as pd
import numpy as np
df = pd.DataFrame(index=range(0,5), data=[range(5*i,5*i+5) for i in range(0,5)])
df
:
0 1 2 3 4
0 0 1 2 3 4
1 5 6 7 8 9
2 10 11 12 13 14
3 15 16 17 18 19
4 20 21 22 23 24
并打印df.iloc[2,2]
返回12
答案 1 :(得分:0)
For selecting a single value from a DataFrame or Series, at
(label based scalar indexing) and iat
(index based scalar indexing) are generally the fastest.
numbers = []
numbers.append(df.iat(50, 24))
Lets say you had three pairs of numbers representing row and column index values where you want to lookup a value from your DataFrame. You could efficiently accomplish this goal as follows:
pairs = [(10, 20), (20, 25), (30, 30)]
[numbers.append(df.iat(row, col)) for row, col in pairs]