<jupyter_start><jupyter_text>Final Project 'Introduction to Data Analysis' Best method to share a post on Instagram<jupyter_code>import pandas as pd
import numpy as np
import datetime as dt
import seaborn as sns
import matplotlib.pyplot as plt
pd.options.mode.chained_assignment = None
url = 'https://raw.githubusercontent.com/Kobi-Mazuz/Final_task/main/Instagram_Data.csv'
df = pd.read_csv(url)
df.tail()<jupyter_output><empty_output><jupyter_text>We imported the DataFrame and displayed it's last five rows to see what columns we are dealing with and the number of rows.<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 178922 entries, 0 to 178921
Data columns (total 13 columns):
 #   Column                 Non-Null Count   Dtype  
---  ------                 --------------   -----  
 0   User uuid              178922 non-null  int64  
 1   Likes                  178922 non-null  int64  
 2   Days passed from post  178922 non-null  int64  
 3   Likes Score            178922 non-null  float64
 4   Type                   178922 non-null  object 
 5   Numer of Tags          178922 non-null  int64  
 6   Numer of Comments      178922 non-null  int64  
 7   Date Posted            178922 non-null  object 
 8   Year                   178922 non-null  int64  
 9   Month                  178922 non-null  int64  
 10  Day                    178922 non-null  int64  
 11  Hour                   178922 non-null  int64  
 12  Minute                 178922 non-null  int64  
dtypes: float64(1), int64(10), object(2)
memory usage: 17.7+ MB<jupyter_text>We checked for the types of data in each column of the DataFrame.<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>We checked for NaN values in each column of the DataFrame.<jupyter_code>corr_df = df[['Days passed from post',"Likes Score","Numer of Tags","Numer of Comments"]]
corr_df = corr_df.corr(method='spearman')
plt.figure(figsize = (10,5))
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
sns.heatmap(data=corr_df,cmap='Blues', annot=True)
plt.show()<jupyter_output><empty_output><jupyter_text>We searched for correlation between the likes score and the numeric columns of the DataFrame to see the connection between them. *Likes Score is the rate of the likes related to the maximun number of likes the account achieved.<jupyter_code>days_passed_df = df[["Days passed from post","Likes"]]
days_passed_df = days_passed_df.groupby("Days passed from post")[["Days passed from post","Likes"]].mean()
days_passed_df['binned'] = pd.cut(days_passed_df["Days passed from post"],bins=range(0, 300, 50))

fig, ax = plt.subplots()
sns.boxplot(x="binned", y="Likes", data=days_passed_df)
plt.xlabel("Days Passed From Post",fontsize=20)
plt.ylabel("Likes",fontsize=20)
fig.set_size_inches(10, 7)
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new DataFrame including only "Likes" and "Days Passed From Post" columns, we cut the days from 0-250 in a 50 days range into 5 boxplots, the graph shows that there is an increase in both median and the high quarter of each boxplot.  This can be explained by the growing number of likes(stacking).<jupyter_code>comm_df = df[["Numer of Comments", "Likes"]]
likes_mean = comm_df["Likes"].mean()
comm_df = comm_df.groupby("Numer of Comments")["Likes"].mean()
fig, ax = plt.subplots()
sns.stripplot(data=comm_df,label="Number Of Comments")
fig.set_size_inches(10, 7)
plt.xlabel("Number Of Comments",fontsize=25)
plt.ylabel("Likes",fontsize=25)
ax.hlines(y=likes_mean, xmin=-0.2, xmax=0.2, linewidth=2, color='r',linestyle='--',label="Mean")
plt.ylim((0, likes_mean*3))
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new DataFrame with the "Number of Comments" and "Likes" columns. We can see in the stripplot that in any range of likes between 0-120k there is the same number of comments approximatley (no differnece from the mean area marked by the red dotted line).<jupyter_code>tag_df = df[["Numer of Tags", "Likes Score"]]
likes_score_mean = df["Likes Score"].mean()
tag_df = tag_df.groupby("Numer of Tags")["Likes Score"].mean()
fig, ax = plt.subplots()
sns.lineplot(data=tag_df,label="Number Of Tags")
fig.set_size_inches(10, 7)
plt.xlabel("Number Of Tags",fontsize=20)
plt.ylabel("Likes Score",fontsize=20)
ax.hlines(y=likes_score_mean, xmin=0, xmax=32, linewidth=2, color='r',linestyle='--',label="Mean")
plt.xticks(np.arange(0, 32, 1))
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new DataFrame with the "Number of Tags" and "Likes Score" columns. We used the "Likes Score" column to check the rate between each acccount individualy to keep the data valid. The data shows that there isn't a growing rate to the "Likes Score" column mean when the "Number of Tags" column is growing.<jupyter_code>type_df = df[["Type", "Likes Score"]]
sns.catplot(data=type_df, kind="bar", x="Type", y = "Likes Score",height=5,aspect=1.8)
plt.xlabel("Type",fontsize=20)
plt.ylabel("Likes Score",fontsize=20)
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new DataFrame with the "Type" and "Likes Score" columns and showed the mean rate of "Likes Score" in each type: "Image", "Images" and "Video". The graph shows that the "Images" type is getting the highest rate of "Likes Score", with "Image" afterwards and "Video" last.<jupyter_code>month_df = df[["Month","Likes Score"]]
month_plot = sns.catplot(x="Month",
            y="Likes Score", 
            data=month_df, 
            kind='bar',
            height=5,
            aspect=2.4)
plt.ylim((0.25, 0.3))
plt.xticks(np.arange(0, 12, 1))
month_plot.map(plt.axhline, y=likes_score_mean, ls='--', color='r', linewidth=2)
plt.xlabel("Month",fontsize=20)
plt.ylabel("Likes Score",fontsize=20)
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new DataFrame with the "Month" and "Likes Score" columns and showed the mean rate of "Likes Score" in every month. The graph shows that there are four months with a mean value of likes score higher than avarage - July, August, December and January.<jupyter_code>week_days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
df['Date Posted'] = pd.to_datetime(df['Date Posted'])
df['Day Name']=df['Date Posted'].dt.strftime("%A")
day_df = df[["Day Name","Likes Score"]]
day_plot = sns.catplot(x="Day Name",
            y="Likes Score", 
            data=day_df, 
            kind='bar',
            height=5,
            aspect=2.4,
            order= week_days)
plt.ylim((0.25, 0.3))
plt.xticks(np.arange(0, 7, 1))
day_plot.map(plt.axhline, y=likes_score_mean, ls='--', color='r', linewidth=2)
plt.xlabel("Day Of The Week",fontsize=20)
plt.ylabel("Likes Score",fontsize=20)
plt.show()<jupyter_output><empty_output><jupyter_text>We created a new column named "Day Name" which shows the day of the week from the "Date Posted" column. Than we created a new DataFrame with the "Day Name" and "Likes Score" columns and showed the mean rate of "Likes Score" in every day of the week. The graph shows that there are three days with a higher likes score than avarage - Sunday, saturday and monday by that order.<jupyter_code>hour_min_df = df[["Likes Score","Hour","Minute"]]
hour_min_df["Hour"] = round(df["Hour"]+df["Minute"]/60)
hour_min_df.drop(["Minute"],axis=1,inplace=True)
hour_plot= sns.catplot(x="Hour",
            y="Likes Score", 
            data=hour_min_df, 
            kind='bar',
            height=5,
            aspect=2.4)
plt.ylim((0.22, 0.32))
plt.xticks(np.arange(0, 25, 1))
hour_plot.map(plt.axhline, y=likes_score_mean, ls='--', color='r', linewidth=2)
plt.xlabel("Hour",fontsize=20)
plt.ylabel("Likes Score",fontsize=20)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12885334709144847, 'fraction_numerical': 0.033922352637688634, 'mean_word_length': 4.282016348773842, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '120465', 'license': 'CC0-1.0', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2638, 'n_words': 759, 'path': 'projects-spring-2021/K.ipynb', 'repo_name': 'YuLe33/data-analytics', 'size': '7753'}