2017年7月12日 星期三

[ Python 常見問題 ] Pandas - How to get a value from a cell of a data frame?

Source From Here 
Question 
For example: 
>>> import pandas as pd 
>>> John = pd.Series(['John', 36, 'Male']) 
>>> Mary = pd.Series(['Mary', 23, 'Female']) 
>>> people_df = pd.DataFrame([list(John), list(Mary)], columns=['Name', 'Age', 'Sex']) 
>>> people_df // Show content of dataframe 
Name Age Sex 
0 John 36 Male 
1 Mary 23 Female

How do I access the 'Age' of second Series (Here is 23)? 

How-To 
Using DataFrame.iloc (Purely integer-location based indexing for selection by position.): 
>>> people_df.iloc[1]['Age'] 
23


沒有留言:

張貼留言

[ Python 常見問題 ] Get all object attributes in Python?

Source From  Here   Question   Is there a way to  get all attributes/methods/fields/etc. of an object in Python ?  vars()  is close to what ...