Computing Programming With Python (W10)
Computing Programming With Python (W10)
CLASS
CONTENTS
Pandas Library
Evolution
Click me
Find how to
connect Kaggle
with Python
For the next Class
df.attribute description
dtypes list the types of the columns
df.method() description
head( [n] ), tail( [n] ) first/last n rows
method);
a new dataframe
➢ Calculate the mean value for each numeric column per each group
Data Frames groupby method
● Once groupby object is create we can calculate
various statistics for each group:
Note: If single brackets are used to specify the column (e.g. total_days), then the output is Pandas Series
object. When double brackets are used the output is a Data Frame
Data Frame: filtering
To subset the data we can apply Boolean indexing. This
indexing is commonly known as a filter. For example if
we want to subset the rows in which the total_days
value is greater than 365 days:
When we need to select more than one column and/or make the
output to be a DataFrame, we should use double brackets:
Data Frames: Selecting rows
If we need to select a range of rows, we can specify the range using “:”
Note: The first row has a position 0, and the last value in the range is omitted:
So for 0:10 range the first 10 rows are returned with the position starting with
0 and ending with 9
Data Frames: method loc
If we need to select a range of rows, using their labels we can use method loc:
Data Frames: method iloc
If we need to select a range of rows and/or columns, using their positions we
can use method iloc:
Data Frames: method iloc
If we need to select a range of rows and/or columns, using their positions we
can use method iloc:
Data Frames: Sorting
We can sort the data by a value in the column. By default the sorting will
occur in ascending order and a new data frame is return.
Practice:
Create a new data frame from the original sorted by the column total_days
Data Frames: Sorting
We can sort the data using 2 or more columns:
Practice:
Create a new data frame from the original sorted by the column total_days and
datetime column
Missing Values
# Select the rows that have at least one missing value
df[df.isnull().any(axis=1)].head()
Missing Values
df.method() description
dropna() Drop missing observations
min, max
count, sum, prod
mean, median, mode, mad
std, var
Aggregation Functions in Pandas
agg() method are useful when multiple statistics are computed per
column:
df[[column1,column2]].agg(['min','mean','max'])
For the next class:
Q&A
Every question is welcome be
free to express your thoughts
Gracias!!!
Thank you
감사합니다