import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
import warnings as ws
ws.filterwarnings("ignore")
df = pd.read_csv("/kaggle/input/ipl2020-tweets/IPL2020_Tweets.csv")
df.head()
"""
<center style = "color: #e11d74" > <h1> Dealing with the Missing values </h1> </center>
"""
check_na = ((df.isna().sum() / df.shape[0])* 100).reset_index().rename(columns = {"index": "Columns", 0: "missing value percentage"})
fig = px.bar(check_na, y='missing value percentage', x='Columns', text='missing value percentage', title = "Percent of missing values in the columns")
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:18px;">The  Column <i> User Location hss </i> has the maximum no. of missing values. followed by the user_description  </p>
    
  
"""
"""
# Dealing with user Location
"""
sns.set()
plt.figure(figsize = (10,6))
sns.barplot(data = df.user_location.value_counts()[:5].reset_index(), y = "user_location", x="index", palette="Spectral") 
plt.ylabel("Count of people")
plt.xlabel("Top Locations in the dataser")
plt.title("Top user locations in the dataset", size = 20)
plt.show()

# For the purpose of EDA we will replace the na values of location with the  india
df.user_location.fillna("India", inplace= True)
df.hashtags.fillna('[IPL2020]' , inplace = True)
df.isna().sum()
"""
<div>
    <p style = "color: #322f3d; font-size:22px;"> All NaN values filled except user description which i prefereed not to fill  </p>
    
    
  
"""
"""
<h1 style ="color: #6f4a8e;"> Begin </h1> 
"""
# estimate of verified user
temp = df.user_verified.replace({True: "Verified", False: "Non-verfied"}).value_counts().reset_index()
fig = px.pie(temp, values='user_verified', names='index', color_discrete_sequence=px.colors.sequential.RdBu, title = "User Status")
fig.show()


"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:18px;">Clear intuaition is most peoples are NOT verfied. As the twitter is prestigious platform still it is  suffering to verify the peoples. </p>
    
  

"""
fig = px.bar(df.source.value_counts()[:10].reset_index(), y='source', x='index', text='source', title = "Top Sources of posting", color = "index")
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:18px;">Most people tends to use the twitter on the Android  phones followed by the Twitter Web app and Twitter on Iphone </p>
    
  



"""
fig = px.bar(df.hashtags.value_counts()[1:10].reset_index(), y='hashtags', x='index', text='hashtags', title = "Top Trending of Hashtags",  color='index')
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:19px;">AS the BCCI announces the organization of the IPL hence it become the trending toics followed by the Dream11 </p>
    
  



"""
fig = px.scatter(data_frame=df, y="user_favourites", x="user_followers", size = "user_favourites", color = "user_verified",log_x=True, size_max=20)
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:18px;">Verification is still the issue here</p>

"""
fig = px.bar(df.user_location.value_counts()[:20].reset_index(), y='user_location', x='index', text='user_location', title = "Top 20 locations while twitting ",  color='index')
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:18px;">As india's digital literacy is growing and the data rates are quite cheap the consumption is also increased. We can clearly build the intuiation that india is one of the biggest digital market.</p>

"""
df.user_created = pd.to_datetime(df.user_created, infer_datetime_format=True)
temp = pd.datetime.now() - df.user_created
avg_age = []
for i in temp:
    avg_age.append(int(str(i).split()[0]) // 365)
fig = px.bar(pd.Series(avg_age).value_counts().reset_index().rename(columns = {"index":"year", 0:"Occurances"}), x= "year", y="Occurances", color = "Occurances", title  ="Age of the twitter account ")
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- (Tricky) </p>
        <p style = "color: #1b262c; font-size:18px;">This is the most interesting graph. This is the distribution of the age of the people on the youtube. This assumes the creation date as thebirth and hence i calculated the age uptill today </p>

"""
temp = df.is_retweet.value_counts().reset_index().replace({False: "Not Retweeted", True : "ReTweeted"})
fig = px.pie(temp, values='is_retweet', names='index', color_discrete_sequence=px.colors.sequential.RdBu, title = "Retweeted or not")
fig.show()
"""
<div>
    <p style = "color: #d54062; font-size:22px;"> Inference :- </p>
        <p style = "color: #1b262c; font-size:20px;">No one Retweeted</p>

"""
"""
<hr style = "font-size:20px;">
"""
"""
<div> 
    <h1 style = "color: #cf1b1b; font-weight:bold"> Final Conclusions </h1>
    <ul>
        <li style = "color: #440047; font-size:18px; margin: 1.5rem;">Text Based features have lot of NaN values</li>
        <li  style = "color: #440047; font-size:18px; margin: 1.5rem;"> Absence of continous features gives us chance to derive new one</li>
        <li  style = "color: #440047; font-size:18px; margin: 1.5rem;"> Indians are posting lot of tweets</li>
        <li  style = "color: #440047; font-size:18px; margin: 1.5rem;" > IPL is one of the Hot Topics</li>
        <li  style = "color: #440047; font-size:18px; margin: 1.5rem;"> Most users are Non - verified</li>
        <li  style = "color: #440047; font-size:18px; margin: 1.5rem;"> Most peoples used their phones For their tweets</li>
        </ul>
"""
"""
<center> <h1 style = "color: #fa163f; font-weight:bold"> ^^^ UPVOTE IT ^^^  </h1> </center>

"""