Entwicklung mit Python für Fortgeschrittene
Jasmin Ludolf
Senior Data Science Content Developer
Modul = Python-Datei
Jeder kann eine Python-Datei erstellen!


Terminal / Eingabeaufforderung
python3 -m pip install <package_name>
python3 führt Python-Code vom Terminal aus
pip: Bevorzugtes Installationsprogramm
python3 -m pip install pandas

$$
# Import pandas
import pandas
# 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)print(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 print(type(sales_df))
pandas.core.frame.DataFrame
# DataFrame method to preview the first five rows
print(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
# Checking the file info
print(sales_df.info())
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
# Column Non-Null Count Dtype
<hr /> ------ -------------- -----
0 user_id 3 non-null object
1 order_value 3 non-null float64
dtypes: float64(1), object(1)
memory usage: 180.0+ bytes
# This is a built-in function
print(sum([1, 2 ,3, 4, 5]))
15
# This is a pandas function
sales_df = pd.DataFrame(sales)
.head() funktioniert nur mit pandas-dataframes.# This is a method
print(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
Entwicklung mit Python für Fortgeschrittene