This question already has an answer here:
这个问题在这里已有答案:
Pandas - 获取给定列5个答案的第一行值
Is that any way that I can get first element of Seires without have information on index.
这是否可以获得Seires的第一个元素而没有索引信息。
For example,We have a Series
例如,我们有一个系列
import pandas as pd
key='MCS096'
SUBJECTS=pd.DataFrame({'ID':Series([146],index=[145]),\
'study':Series(['MCS'],index=[145]),\
'center':Series(['Mag'],index=[145]),\
'initials':Series(['MCS096'],index=[145])
})
prints out SUBJECTS:
打印出SUBJECTS:
print (SUBJECTS[SUBJECTS.initials==key]['ID'])
145 146
Name: ID, dtype: int64
How can I get the value here 146 without using index 145?
如何在不使用索引145的情况下获取此值146?
Thank you very much
非常感谢你
52
Use iloc to access by position (rather than label):
使用iloc按位置访问(而不是标签):
In [11]: df = pd.DataFrame([[1, 2], [3, 4]], ['a', 'b'], ['A', 'B'])
In [12]: df
Out[12]:
A B
a 1 2
b 3 4
In [13]: df.iloc[0] # first row in a DataFrame
Out[13]:
A 1
B 2
Name: a, dtype: int64
In [14]: df['A'].iloc[0] # first item in a Series (Column)
Out[14]: 1
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/06/17/384f608f6d3e4c7804d115eb5dd157ae.html。