Intermediate Python for Developers
George Boorman
Curriculum Manager, DataCamp
Module = Python file
Anyone can create a Python file!
python3 -m pip install <package_name>
python3
- Used to execute Python code from the terminalpip
- Preferred Installer Program
python3 -m pip install pandas
# Import pandas
import pandas
pandas
before every function# Import pandas using an alias
import pandas as pd
# Sales dictionary sales = {"user_id": ["KM37", "PR19", "YU88"], "order_value": [197.75, 208.21, 134.99]}
# Convert to a pandas DataFrame sales_df = pd.DataFrame(sales)
sales_df
user_id order_value
0 KM37 197.75
1 PR19 208.21
2 YU88 134.99
# Reading in a CSV file in our current directory sales_df = pd.read_csv("sales.csv")
# Checking the data type type(sales_df)
pandas.core.frame.DataFrame
# DataFrame method to preview the first five rows
sales_df.head()
user_id order_value
0 KM37 197.75
1 PR19 208.21
2 YU88 134.99
3 NT43 153.54
4 IW06 379.47
Function = code to perform a task
Method = a function that is specific to a data type
# This is a built-in function
sum([1, 2 ,3, 4, 5])
15
# This is a pandas function
sales_df = pd.DataFrame(sales)
.head()
won't work with other data types:# This is a method
# It is specific to a DataFrame data type
sales_df.head()
user_id order_value
0 KM37 197.75
1 PR19 208.21
2 YU88 134.99
3 NT43 153.54
4 IW06 379.47
Intermediate Python for Developers