text_html_output_1.png
import json

import pandas as pd

import seaborn as sns

import warnings

import numpy as np
import pandas as pd
import json
import seaborn as sns
sns.set_style('whitegrid')
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import nltk
from nltk.corpus import stopwords
from wordcloud import WordCloud, STOPWORDS
import warnings
warnings.filterwarnings(action='ignore')
pd.set_option('display.max_columns', 50)

df = pd.read_csv('/kaggle/input/youtube-new/USvideos.csv')

df.insert(5, 'publish_date', df['publish_time'].dt.date)

id_to_cat = {}
with open('/kaggle/input/youtube-new/US_category_id.json', 'r') as f:
    data = json.load(f)
    for category in data['items']:
        id_to_cat[category['id']] = category['snippet']['title']

df.insert(5, 'category', df['category_id'].map(id_to_cat))

df.insert(8, 'publish_to_trend_days', df['trending_date'] - df['publish_date'])

df.insert(7, 'publish_month', df['publish_date'].dt.strftime('%m'))

df.insert(8, 'publish_day', df['publish_date'].dt.strftime('%a'))

df.insert(10, 'publish_hour', df['publish_time'].apply(lambda x: x.hour))

df.head()