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

# ## Exercise 3:
#

# +
id1 = "314096637"
id2 = "318879533"

name_student_1 = "<NAME>"
name_student_2 = "<NAME>"

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import datetime as dt
df = pd.DataFrame([id1,id2])
# Uncomment in case two students are doing the assignment together
# df = pd.DataFrame([id1])df = pd.DataFrame([id1,id2])
df.to_clipboard(index=False,header=False)

url = "https://raw.githubusercontent.com/nlihin/data-analytics/main/datasets/youtube/youtube_US_short.csv"
data = pd.read_csv(url)
data.head()
# -

Maxviews = data[data["views"] == data.views.max()]
MaxViews = Maxviews.groupby('title')[['publish_time','views']].max()
MaxViews

Channel_title = data.groupby('channel_title')[['views']].sum()
TopChannel = pd.DataFrame(Channel_title['views'].nlargest(3))
TopChannel

CorrSpearman = data[['likes', 'dislikes','views','comment_count']].corr(method = 'spearman')
CorrSpearman

plt.figure(figsize=(8,6))  
sns.heatmap(CorrSpearman, cmap='ocean', center=0, annot = True)

fig,axis = plt.subplots(1,2,figsize = (12,5))
up_correr = CorrSpearman.unstack().sort_values()[-7:-5]
upper = pd.Series.keys(up_correr)
sns.scatterplot(ax = axis[0], data = data, x = upper[0][0], y = upper[0][1])
sns.scatterplot(ax = axis[1], data = data, x = upper[1][0], y = upper[1][1])

data['publish_time'] = pd.to_datetime(data['publish_time'])
data['year'] = pd.DatetimeIndex(data['publish_time']).year
maxby = data[(data.year == 2017)| (data.year == 2018)]
maxby.pivot_table('views',index='category_id', columns='year',margins=True , aggfunc='sum')

StarcoderdataJupyterScriptsDedupFiltered