Pandas PD Scipy Matplotlib - Pyplot PLT Matplotlib - Ticker TK Numpy NP
Pandas PD Scipy Matplotlib - Pyplot PLT Matplotlib - Ticker TK Numpy NP
[4]: df = pd.read_csv('shopeep_koreantop_clothing_shop_data.csv')
df.info()
df.tail(10)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 746 entries, 0 to 745
Data columns (total 18 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 pk_shop 746 non-null int64
1 date_collected 746 non-null object
2 shopid 746 non-null int64
3 name 746 non-null object
4 join_month 746 non-null object
5 join_day 746 non-null int64
6 join_year 746 non-null int64
7 item_count 746 non-null int64
8 follower_count 746 non-null int64
9 response_time 746 non-null object
10 response_rate 746 non-null int64
11 shop_location 428 non-null object
12 rating_bad 746 non-null int64
13 rating_good 746 non-null int64
14 rating_normal 746 non-null int64
15 rating_star 740 non-null float64
16 is_shopee_verified 746 non-null int64
17 is_official_shop 746 non-null int64
dtypes: float64(1), int64(12), object(5)
memory usage: 105.0+ KB
1
[4]: pk_shop date_collected shopid name \
736 20210706325618926 2021-07-06 325618926 Be Young Life
737 20210706416886409 2021-07-06 416886409 vaapo.ph
738 20210706419954100 2021-07-06 419954100 Fall in love with you
739 2021070664360491 2021-07-06 64360491 Yzkzks.ph
740 2021070616590993 2021-07-06 16590993 Adol Janet
741 20210706449182992 2021-07-06 449182992 Yacent_thrift_Clo
742 20210706396605392 2021-07-06 396605392 Akistore.ph
743 20210706360379308 2021-07-06 360379308 Yzanice Shop
744 2021070629392066 2021-07-06 29392066 Clairecvc Shop
745 2021070625811092 2021-07-06 25811092 angelcity.�
2
[5]: # Hàm tính các hệ số Linear Regression, gồm các tham số: x, y và DataFrame chứa␣
↪các giá trị x, y
# Hàm dọn các giá trị ngoại biên bằng hệ số Z-Scores (outline cleaner), gồm các␣
↪tham số: 2 thuộc tính cần dọn, DataFrame cần dọn
[6]: fig, axs = plt.subplots(2, 3, figsize=(20,10), dpi=80) # Cài đặt Figure với các␣
↪Axes
# Yêu cầu 1
count_shop = df.groupby(['join_year'])[['join_year']].count() # Số lượng sốp␣
↪theo năm
3
[7]: # Yêu cầu 2
df_sub = o_c('response_rate','rating_good', df) # Truyền 2 thuộc tính và␣
↪DataFrame vào để nhận DataFrame mới được xử lý
df_sub['response_time'] = [(int(e.strftime('%H'))*int(e.
↪strftime('%M'))*60+int(e.strftime('%S'))) for e in df_sub.response_time]
# Phương thức strftime của Python giúp trích xuất thông tin giờ, phút, giây từ␣
↪text
4
# Ép về int do phương thức strftime trả về kiểu str. Tính ra giây: 1 giờ = 60␣
↪phút, 1 phút = 60 giây -> hour*minute*60 + second
df_sub2 = o_c('response_time','rating_bad',df_sub)
axs[0,2].plot(df_sub2.response_time, a1[0]*df_sub2.response_time+a1[1],␣
↪color='r')
year = df_sub['join_year']
month = df_sub['join_month']
day = df_sub['join_day']
combin = ['{} {} {}'.format(year[i], month[i], day[i]) for i in␣
↪range(len(df_sub.index))] # Hợp các giá trị thời gian lại để phục vụ mục␣
↪đích xử lý
df['join_time'] = combin # Tạo một cột mới trong bộ dữ liệu để thêm các giá trị␣
↪thời gian vừa hợp vào
# Xử lý thời gian dạng text sang datetime object, các ký tự anh em xem thêm tại␣
↪link dưới để hiểu
# https://www.geeksforgeeks.org/python-datetime-strptime-function/
# https://stackoverflow.com/questions/25146121/
↪extracting-just-month-and-year-separately-from-pandas-datetime-column
count_join = df_sub.groupby(df_sub.join_time.dt.to_period('M'))[['join_time']].
↪count() # Nhóm theo tháng, hoặc anh em thích nhóm theo ngày thì chuyển M ->␣
5
axs[1,0].plot(np.asarray([str(e) for e in count_join.index]),count_join.
↪join_time, linewidth=3, marker='*', markersize=10, markerfacecolor='red')
C:\Users\Dell\AppData\Local\Temp\ipykernel_11072\1038879872.py:26: UserWarning:
FixedFormatter should only be used together with FixedLocator
axs[1,0].set_xticklabels(axs[1,0].get_xticklabels(), rotation=45) # the same
[ ]: