[PYTHON] Summary of what was used in 100 Pandas knocks (# 1 ~ # 32)
Introduction
I am studying ** machine learning ** at university. For review, I tried ** Pandas 100 knocks **.
The function you used? I would like to summarize.
Pandas 100 knocks
Click here for details
Pandas 100 knocks for Python beginners
Pandas Basics (1 ~ 13)
# 1 Show first 5 lines of DataFrame
df.head()
When specifying the number of lines you want to display
Example: 10 lines
df.head(10)
# 2 Show last 5 lines
df.tail()
# 5 df'fare' sorted in ascending order and displayed
df.sort_values('fare')
Sort in descending order by specifying ** ascending = False **
Data extraction (14 ~ 32)
# 18 Use loc to view the entire df
df.loc[:,:]
Use # 20 loc to display up to the 10th row of the df fare column
df.loc[:10, 'fare']
Extract only data whose age column value of # 25 df is 30 or more
df[df['age'] >= 30]
Extract only data with # 27 df sex column female and age 40 or more
df[(df['sex'] == "female") & (df['age'] >= 40)]
Extract only data whose df sex column is female and age is 40 or more using # 28 query
df.query('sex == "female" & age >= 40')
Display data containing the character string "Mrs" in the name column of # 29 df
df.query('name.str.contains("Mrs")', engine='Python')
# 30 Show only character columns in df
df.select_dtypes(include='object')
# 31 Check the number of elements in each column of df
df.nunique()
Check the elements of the embarked column of # 32 df and the number of occurrences
df['embarked'].value_counts()
Impression that I tried halfway
I felt like I was getting used to Pandas, but when I tried it, my confidence was broken ...
It will be a good review, so please try it even if you are accustomed to it.
query Very convenient ...