# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import chi2_contingency

apps_df = pd.read_csv("datasets/googleplaystore.csv")
apps_df.head()

# Information of the data

apps_df.info()

apps_df.isnull().sum()


# Drop rows with missing data(?)

apps_df.dropna(how ='any', inplace = True)
apps_df.shape

apps_df.boxplot()

apps_df.drop(apps_df[apps_df['Rating'] > 5].index, inplace = True)
apps_df.boxplot()

# Convert non-numerical values into numerical data

apps_df['Price'] = apps_df['Price'].str.replace('$','').astype(float)

# +
apps_df['Installs'] = apps_df['Installs'].str.replace('+','')
apps_df['Installs'] = apps_df['Installs'].str.replace(',','')
apps_df['Installs'] = pd.to_numeric(apps_df['Installs'], downcast="float")

apps_df['Reviews'] = pd.to_numeric(apps_df['Reviews'])
apps_df.head()
# -

apps_df['Reviews'] = pd.to_numeric(apps_df['Reviews'])

# Fill empty cells in Type, Current Ver, and Android Ver with mode

apps_df['Type'].fillna(str(apps_df['Type'].mode().values[0]),inplace=True)
apps_df['Current Ver'].fillna(str(apps_df['Current Ver'].mode().values[0]),inplace=True)
apps_df['Android Ver'].fillna(str(apps_df['Android Ver'].mode().values[0]),inplace=True)
apps_df.isnull().sum()

# Some apps have a genre and a sub genre. Make two new columns for genre and sub genre. Apps with no subgenre will have their primary genre listed as their sub genre
#

newCol = apps_df.Genres.apply(lambda x: x.split(';')[0])
apps_df["Genre"] = newCol
newCol = apps_df.Genres.apply(lambda x: x.split(';')[-1])
apps_df["SubGenre"]=newCol
apps_df.head()

apps_df.hist("Rating")
plt.ylabel('Frequency')
plt.show()

apps_df.describe()

# Average rating of an app is 4.19

category_count = apps_df['Category'].value_counts()
category_count.plot.bar()
plt.title("Number of apps in each category")
plt.ylabel("Count")
plt.show

apps_df.boxplot("Rating", by="Category", figsize=(15,10))
plt.xticks(rotation='vertical')
plt.ylabel("Rating")
plt.xlabel("Category")
plt.show()

# The ratings of apps across all categories are similar?

#

apps_df.boxplot("Rating", by="Genre", figsize=(15,10))
plt.xticks(rotation='vertical')
plt.ylabel("Rating")
plt.xlabel("Genre")
plt.show()

apps_df.groupby(['Genre', 'SubGenre']).size().unstack().plot(kind='bar', stacked='True', figsize=(15,15))
plt.xlabel('Genres')
plt.ylabel('Count')
plt.title('Genres and their subgenre')
plt.legend(bbox_to_anchor=(1.0,1.0))
plt.show()

apps_df.hist("Reviews",bins=1000000)

plt.plot(apps_df['Price'], apps_df['Category'], 'r+')
plt.xlabel('Price')
plt.ylabel('Category')
plt.title('App price trends across categories')

# There are apps over $100 in price, most likely to be scam apps

print(apps_df[["App","Price"]][apps_df.Price > 100].count())
apps_df[["App","Price"]][apps_df.Price > 100]

removedScamAppsDF = apps_df[apps_df.Price<100]
plt.plot(removedScamAppsDF['Price'], removedScamAppsDF['Category'], 'r+')
plt.xlabel('Price')
plt.ylabel('Category')
plt.title('App price trends across categories')

plt.plot(apps_df['Price'], apps_df['Rating'], 'r+')
plt.xlabel('Price')
plt.ylabel('Rating')
plt.title('App price trends across categories')

StarcoderdataJupyterScriptsDedupFiltered