text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

udemy_courses = pd.read_csv('/kaggle/input/udemy-courses/udemy_courses.csv', parse_dates=['published_timestamp'])

udemy_courses['price'] = udemy_courses['price'].str.replace('Free', '0').str.replace('TRUE', '0')
udemy_courses['price'] = udemy_courses['price'].astype('float')
udemy_courses['number_of_contents'] = udemy_courses['content_duration'].str.extract('([\\d\\.]+)\\s[\\w]+').astype('float')
udemy_courses['content_duration_type'] = udemy_courses['content_duration'].str.extract('[\\d\\.]+\\s([\\w]+)')
udemy_courses.drop('content_duration', axis=1, inplace=True)

udemy_courses.dropna(inplace=True)

g=sns.catplot(x='subject',
            data=udemy_courses,
            kind='count',
            hue='is_paid')
g.fig.suptitle('free/paid categories comparison', y=1.03)
plt.xticks(rotation=90)
plt.show()

g=sns.catplot(x='level',
            data=udemy_courses,
            kind='count',
            hue='is_paid')
g.fig.suptitle('free/paid lavel comparison', y=1.03)
plt.xticks(rotation=90)
plt.show()

# Box-plot, CDF, histogram
def cdf(lst):
    x=np.sort(lst)
    y=np.arange(1, len(x)+1)/len(x)
    return x, y
fig, ax=plt.subplots(1,3, figsize=(15,5))
x_price, y_price=cdf(udemy_courses['price'])
ax[0].plot(x_price, y_price)
ax[0].set_title('CDF of prices')
ax[1].hist(udemy_courses['price'])
ax[1].set_title('histogram distribution of prices')
ax[2].boxplot(udemy_courses['price'])
ax[2].set_title('boxplot of prices')
plt.show()
print('median: ',udemy_courses['price'].median())
print('mean: ',udemy_courses['price'].mean())

udemy_courses.groupby('price_category')['num_lectures'].mean().sort_values(ascending=False)

mins_courses=udemy_courses[udemy_courses['content_duration_type']=='mins']
g=sns.catplot(x='price_category',
            data=mins_courses,
            kind='count',
            hue='level')
g.fig.suptitle("price category (minutes courses) in each level.", y=1.03, x=0.4)
plt.show()

udemy_courses['published_timestamp'].dt.year.value_counts().plot.bar()
plt.xlabel('published year')
plt.ylabel('frequency')
plt.title('number of courses published each year(2011-2017)')
plt.show()