# ---
# 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
# ---

# + _cell_guid="b1076dfc-b9ad-4769-8c92-a6c4dae69d19" _uuid="8f2839f25d086af736a60e9eeb907d3b93b6e0e5"


import numpy as np 
import pandas as pd




# -

df=pd.read_csv(r"C:\Users\Om\Machine_learning\googleplaystore.csv")
df1=df.copy()
df.head()

df.columns

df.shape

df.isnull().any()

df.isnull().sum()

import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline

df.info()

df.describe()

# + active=""
#
# -

df.at[10472,'Last Updated']='February 11, 2018'
df.at[10472,'Genres']= np.nan
df.at[10472, 'Type']= 'Free'
df.at[10472, 'Price']= 0
df.at[10472, 'Size']= '3.0M'
df.at[10472, 'Installs']= "1,000+"
df.at[10472, 'Rating']= 1.9
df.at[10472, 'Reviews']= 19.0
df.at[10472, 'Content Rating']= 'Everyone'
df.at[10472, 'Category'] = np.nan


df.iloc[10472]

import datetime
df["date of last update"]=pd.to_datetime(df["Last Updated"])
df.head()

df.drop("Last Updated",axis=1)
df.head()

from sklearn.preprocessing import StandardScaler 
from sklearn.preprocessing import OrdinalEncoder

df.info()
df.head()

df.Category.value_counts()

plt.figure(figsize=(10,10))
sns.countplot(y=df["Category"],data=df,)
plt.show()

df["Type"].value_counts()

sns.countplot(x=df["Type"],data=df)
plt.grid(True)

df["Size"]=df.Size.apply(lambda x:x.strip("+"))
df["Size"]=df.Size.apply(lambda x:x.replace(',',''))
df["Size"]=df.Size.apply(lambda x:x.replace(",",""))


df["Size"]=df.Size.apply(lambda x:x.replace("M","e+6"))
df["Size"]=df.Size.apply(lambda x:x.replace("k",'e+3'))
df["Size"]=df.Size.replace('Varies with device',np.NaN)

df["Size"]=pd.to_numeric(df["Size"])

df["Reviews"]=df["Reviews"].astype(int)
df.info()

df.head()

df.drop("Last Updated",1,inplace=True)

df.dropna(inplace=True)
df.info()

# +

encoder=OrdinalEncoder()
df['enc_Category']=encoder.fit_transform(df[["Category"]])
df['enc_Genres']=encoder.fit_transform(df[["Genres"]])
df.tail()


# +
#df["Size"]=df.Size.apply(lambda x:x.strip("+"))
#df["Size"]=df.Size.apply(lambda x:x.replace(',',''))
#df["Size"]=df.Size.apply(lambda x:x.replace(",",""))





df["Installs"]=df.Installs.apply(lambda x:x.strip("+"))
df["Installs"]=df.Installs.apply(lambda x:x.replace(",",""))
df["Installs"]=df.Installs.astype(int)
df.head()

# -

df.info()

print(df["Price"].unique())
print(df["Price"].dtype)

#df["Size"]=df.Size.apply(lambda x:x.strip("+"))
#df["Size"]=df.Size.apply(lambda x:x.replace(',',''))
#df["Size"]=df.Size.apply(lambda x:x.replace(",",""))
df["Price"]=df.Price.apply(lambda x:x.strip("$"))
df["Price"]=df.Price.astype(float)
df.Price.unique()

df.info()

# +
cat_df=pd.DataFrame(df['Category'].value_counts().reset_index().rename(columns={"index":"Categories","Category":"Count"}))

cat_lst=list(cat_df["Categories"])




plt.figure(figsize=(20,10))
plt.title("No. of Installs per Category")

ax=sns.barplot(x=df["enc_Category"],y=df["Installs"])
ax.set(ylabel="Installs in Millions")
ax.set_xticklabels(cat_lst,rotation=45)
plt.show()
# -

df.Type.value_counts()
vals=[7146,577]
labels=["Free","Paid"]
plt.pie(vals,labels=labels,autopct="%0.2f%%",explode=[0,0.2],radius=1.6)
plt.show()

df.info()

plt.figure(figsize=(10,8))
sns.countplot(y="Rating",data=df)

plt.figure(figsize=(12,10))
plt.title("Rating for each Categories")
ax=sns.barplot(x=df["enc_Category"],y=df["Rating"])
ax.set_xticklabels(cat_lst,rotation=45)
plt.show()

df.info()


def top_Apps(str):
    str=str.upper()
    top=df[df["Category"]==str]
    top_app=top.sort_values(by="Installs",ascending=False).head(3)
    
    plt.figure(figsize=(10,8))
    plt.title("Top Apps For Each Category")
    ax=sns.barplot(x=top_app.App,y=top_app.Installs)
    ax.set_xticklabels(top_app.App,rotation=60)
    plt.show()


top_Apps("SOCIAL")

# +
top_paid=df[df["Type"]=="Paid"].sort_values(by="Price",ascending=False).head(10)
vals=top_paid["Installs"]
labels=top_paid["App"]
#plt.title("Top Paid Apps",fontsize=20,loc="center")
plt.pie(vals,labels=labels,radius=3.5,autopct="%0.1f%%",startangle=60,explode=[0.3,0.2,0,0.5,0.7,0.3,0.4,0.5,0.3,0.4])
plt.legend(labels,loc="best",fontsize=6)



plt.show()


# +
plt.figure(figsize=(8,8))
plt.title("CORRELATION HEATMAP OF THE DATA",fontsize=25)
corr=df.corr()

ax=sns.heatmap(corr,annot=True)
plt.show()
# -









StarcoderdataJupyterScriptsDedupFiltered