35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
![]() |
import zipfile
|
||
|
import numpy as np
|
||
|
import pandas as pd
|
||
|
from sklearn import preprocessing
|
||
|
|
||
|
with zipfile.ZipFile('covid-world-vaccination-progress.zip', 'r') as zip_ref:
|
||
|
zip_ref.extractall(".")
|
||
|
|
||
|
df = pd.read_csv('country_vaccinations.csv')
|
||
|
# podział danych na train/validate/test (6:2:2) za pomocą biblioteki numpy i pandas
|
||
|
train, validate, test = np.split(df.sample(frac=1), [int(.6*len(df)), int(.8*len(df))])
|
||
|
|
||
|
# Wypisanie ilości elementów w poszczególnych ramkach danych
|
||
|
print("Whole set size".ljust(20), df.size)
|
||
|
print("Train set size: ".ljust(20), train.size)
|
||
|
print("Validate set size: ".ljust(20), validate.size)
|
||
|
print("Test set size: ".ljust(20), test.size)
|
||
|
|
||
|
df.describe(include='all')
|
||
|
|
||
|
for col in df.columns:
|
||
|
column = df[col].value_counts().plot(kind="bar",figsize=(30,10))
|
||
|
print("\n", col)
|
||
|
print(column)
|
||
|
|
||
|
# normalizacja wartości numerycznych
|
||
|
numeric_values = df.select_dtypes(include='float64').values # tylko wartości numeryczne
|
||
|
min_max_scaler = preprocessing.MinMaxScaler()
|
||
|
x_scaled = min_max_scaler.fit_transform(values)
|
||
|
numeric_columns = df.select_dtypes(include='float64').columns
|
||
|
df_normalized = pd.DataFrame(x_scaled, columns=numeric_columns)
|
||
|
for col in df.columns: # usunięcie nieznormalizowanych danych i wstawienie nowych już znormalizowanych do oryginalnej ramki danych
|
||
|
if col in numeric_columns: df[col] = df_normalized[col]
|
||
|
|
||
|
df.dropna() # usunięcie wierszy z polami NaN
|