ium_444517/data_expl.py

50 lines
1.8 KiB
Python
Raw Normal View History

2022-04-03 10:54:43 +02:00
import pandas as pd
import numpy as np
data = pd.read_csv('./googleplaystore.csv')
data.dropna(subset=['Rating', 'Type','Content Rating','Current Ver','Android Ver'], inplace=True)
data.reset_index(drop=True, inplace=True)
2022-04-03 13:35:05 +02:00
data = data.drop(columns=["Size", "Android Ver", "Current Ver", "Last Updated"])
2022-04-03 10:54:43 +02:00
# normalizing text
to_lowercase = ['App', 'Category', 'Type', 'Content Rating', 'Genres']
for column in to_lowercase:
data[column] = data[column].apply(str.lower)
data["Installs"] = data["Installs"].replace({'\+': ''}, regex=True)
data["Installs"] = data["Installs"].replace({',': ''}, regex=True)
data["Price"] = data["Price"].replace({'\$': ''}, regex=True)
data["Genres"] = data["Genres"].astype('category')
data["Genres_numeric_value"] = (data["Genres"].cat.codes).astype('float32')
2022-04-03 10:54:43 +02:00
# normalizing numbers
data["Reviews"] = pd.to_numeric(data["Reviews"], errors='coerce')
max_value = data["Reviews"].max()
min_value = data["Reviews"].min()
data["Reviews"] = (data["Reviews"] - min_value) / (max_value - min_value)
data["Installs"] = pd.to_numeric(data["Installs"], errors='coerce')
max_value = data["Installs"].max()
min_value = data["Installs"].min()
data["Installs"] = (data["Installs"] - min_value) / (max_value - min_value)
data["Rating"] = np.asarray(data["Rating"]).astype('float32')
data["Reviews"] = np.asarray(data["Reviews"]).astype('float32')
data["Installs"] = np.asarray(data["Installs"]).astype('float32')
data["Price"] = np.asarray(data["Price"]).astype('float32')
print(data)
2022-04-03 10:54:43 +02:00
# splitting into sets
np.random.seed(123)
train, validate, test = np.split(data.sample(frac=1, random_state=42), [int(.6*len(data)), int(.8*len(data))])
2022-04-03 11:59:09 +02:00
print(f"Data shape: {data.shape}\nTrain shape: {train.shape}\nTest shape: {test.shape}\nValidation shape:{validate.shape}")
2022-04-03 13:49:46 +02:00
train.to_csv('apps_train.csv')
test.to_csv('apps_test.csv')
validate.to_csv('apps_validate.csv')