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


沒有留言:

張貼留言

[Git 文章收集] Differences between git merge and git rebase

Source From  Here Preface Merging and rebasing are the two most popular way to applying changes from one branch into another one. They bot...