Import
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from bokeh.plotting import figure, output_notebook, show
from bokeh.layouts import column
output_notebook()
Filter
# read csf file
df = pd.read_csv('data/actstream.csv', index_col='timestamp', parse_dates=True)
# 특정 열의 값 필터링하기
df = df[(df.actor != 'konolabs') & (df.actor != 'konobeta') & (df.actor != 'test_yun') & (df.actor != 'NBA')
& (df.target != 'konobeta') & (df.target != 'konolabs')
& (df.verb != 'message') & (df.verb != 'member_joined_channel')]
# 특정 행을 그룹하고 특정행을 기준으로 내림차순 정렬
# - actor로 그룹
# - description을 기준으로 내림차순 정렬
res = df.groupby('actor').count().sort_values(['description'], ascending=False).head(20)
Show plots
# matplotlib 으로 그림 출력
x = df.groupby(df.index.date).count().index
y = df.groupby(df.index.date).count()['description']
plt.figure(figsize=(15,5))
plt.plot(x, y)
from bokeh.models import ColumnDataSource, HoverTool
# create a new plot with a title and axis labels
p = figure(title="Daily usages of kono bot",
x_axis_label='날짜', y_axis_label='개수', x_axis_type="datetime",
plot_width=800, plot_height=350)
p.add_tools(HoverTool(
tooltips=[
( 'date', '@{x}{%F}' ),
("total", "@y"),
],
formatters={
'x' : 'datetime', # use 'datetime' formatter for 'date' field
},
))
# add a line renderer with legend and line thickness
p.vbar(x, top=y, legend="Number of messages", width=100, color='blue')
# show the results
show(p)
Get ready for bokeh
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from bokeh.plotting import figure, output_notebook, show
from bokeh.layouts import column
output_notebook()
Necessary python packages
✗ pip install notebook pandas matplotlib bokeh