<jupyter_start><jupyter_text>สถิติการเขียนบทความบน Medium ในปี 2020 ของชาว ODDS<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
plt.rcParams['font.family'] = 'tahoma'
df = pd.read_csv('./data/ODDS Medium Publication - 2020.csv', header=1)
df.head()
df.columns = df.columns.str.lower()
df.info()
df['date_converted'] = pd.to_datetime(df.date, format='%Y/%m/%d')
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 162 entries, 0 to 161
Data columns (total 4 columns):
 #   Column          Non-Null Count  Dtype         
---  ------          --------------  -----         
 0   date            162 non-null    object        
 1   article         162 non-null    object        
 2   author          162 non-null    object        
 3   date_converted  162 non-null    datetime64[ns]
dtypes: datetime64[ns](1), object(3)
memory usage: 5.2+ KB<jupyter_text>ทั้งหมดแล้วเราเขียนกันไปกี่บทความในปี 2020<jupyter_code>df.count()[0]<jupyter_output><empty_output><jupyter_text>จำนวนบทความในแต่ละเดือน<jupyter_code>df_count = df.groupby(df.date_converted.dt.month)[['date']].count().reset_index().rename(columns={'date_converted': 'month', 'date': 'count'})
import calendar
df_count['month_name'] = df_count['month'].apply(lambda x: calendar.month_abbr[x])
plt.figure(figsize=(8, 4))
chart = sns.barplot(data=df_count, x='month_name', y='count')
chart.set_xticklabels(chart.get_xticklabels(), rotation=90);<jupyter_output><empty_output><jupyter_text>แต่ละคนเขียนคนละกี่บทความแล้วในปีนี้ (2020)<jupyter_code>plt.figure(figsize=(15, 8))
chart = sns.countplot(data=df, x='author', order=df.author.value_counts().index)
chart.set_xticklabels(chart.get_xticklabels(), rotation=90);<jupyter_output><empty_output><jupyter_text>ในแต่ละเดือนแต่ละคนเขียนกันคนละกี่บทความนะ?<jupyter_code>months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
year = 2020
nrows, ncols = 4, 3
fig = plt.figure(figsize=(18, 25))
plt.subplots_adjust(hspace=1.5)
for index, month in enumerate(months):
    ax = fig.add_subplot(nrows, ncols, index + 1)
    ax.set_title(f'{month} 2020')
    df_each_month = df[df.date_converted.dt.month == index + 1]
    chart = sns.countplot(data=df_each_month, x='author', order=df_each_month.author.value_counts().index, ax=ax)
    chart.set_xticklabels(chart.get_xticklabels(), rotation=90);<jupyter_output><empty_output><jupyter_text>5 คนที่เขียนบทความเยอะสุด เค้าเขียนเฉลี่ยแล้วเดือนละกี่บทความ?<jupyter_code>df.author.value_counts()[:5] / 12<jupyter_output><empty_output><jupyter_text>บทความทั้งหมดของ ODDS คร่าวๆ แล้วเค้าพูดถึงเรื่องอะไรกันบ้าง? (Word Cloud)Credit: https://python3.wannaphong.com/2017/06/word-cloud-python.html<jupyter_code>from pythainlp.corpus import thai_stopwords
from pythainlp.tokenize import word_tokenize
from wordcloud import STOPWORDS, WordCloud
stopwords = thai_stopwords().union(set(STOPWORDS))
text = ' '.join(df.article)
wordcloud = WordCloud(
    font_path='THSarabunNew.ttf',
    stopwords=stopwords,
    max_font_size=50, 
    max_words=100, 
    regexp=r"[\u0E00-\u0E7Fa-zA-Z']+",
    background_color='white').generate(' '.join(word_tokenize(text)))
plt.figure(figsize=(15, 8))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()<jupyter_output><empty_output><jupyter_text>โค้ดไร้สาระอยู่ด้านล่างนี้ 👇<jupyter_code>new_df = df.groupby([df.date_converted.dt.month, df.author]).count()[['article']].reset_index()
new_df.head()
plt.figure(figsize=(15, 8))
sns.barplot(data=new_df, x='date_converted', y='article', hue='author')
sns.barplot(data=df, x=df.date_converted.dt.month, y=df.author)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1731554587530629, 'fraction_numerical': 0.02885924312551048, 'mean_word_length': 5.893058161350845, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '594475', 'license': 'MIT', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1596, 'n_words': 201, 'path': '2020.ipynb', 'repo_name': 'zkan/odds-medium-publication', 'size': '3673'}