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 文章收集 ] SQLAlchemy quick start with PostgreSQL

Source From   Here   Preface   This is a quick tutorial for getting started with   SQLAlchemy Core API .   Prerequisites   In this quick st...