# timestamp 가 초 단위로 되어있으므로, .astype() 에 datetime64[s] 로 바꿔줍니다.
p_u_filtered['datetime'] = p_u_filtered['Timestamp'].astype("datetime64[s]")
p_u_filtered['hour'] = p_u_filtered['datetime'].dt.hour
p_u_filtered['dow'] = p_u_filtered['datetime'].dt.dayofweek
C:\Users\one\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
"""Entry point for launching an IPython kernel.
C:\Users\one\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:2: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
C:\Users\one\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
This is separate from the ipykernel package so we can avoid doing imports until
p_u_filtered.head()
UserId
ProductId
Rating
Timestamp
datetime
hour
dow
2456
AVM6OR01CPJNQ
B00004TMFE
2.0
1365724800
2013-04-12
0
4
2465
A34M18U6T33YDZ
B00004TMFE
5.0
1396828800
2014-04-07
0
0
2492
A2VOGNBUMXSW13
B00004TMFE
2.0
1357516800
2013-01-07
0
0
2549
A38VDDNZ7A3QM0
B00004TMFE
5.0
1386028800
2013-12-03
0
1
2712
A2RQOO8VYAEZZG
B00004TUBL
3.0
1403136000
2014-06-19
0
3
# 피벗 테이블은 3 가지 컬럼 정보만 필요하므로, 대상이 되는 3 개만 넣어서 새로 만들어준다.
pivot_cleaning = p_u_filtered[['Rating', 'hour', 'dow']]
# 시간, 요일 기준으로 평점정보를 피벗 테이블 한 후 heatmap 으로 확인한다.
# hour 가 0 밖에 없다는 것은, 모든 데이터가 00시에 일괄 집계되어 있음을 의미.
import seaborn as sns
pivoted = pivot_cleaning.pivot_table(index='dow', columns='hour', values='Rating').fillna(0)
sns.heatmap(pivoted)
<matplotlib.axes._subplots.AxesSubplot at 0x1dd9a744828>