我尝试使用plotly来创建散点图,但似乎我的时间戳不是JSON可序列化的?这是我得到的错误:
TypeError <built-in method values of dict object at 0x7f6f3d8ac910> is not JSON serializable
这是我目前的代码:
df = datasets[3]
#New column with hour rounded
df['hour'] = df['p_time'].dt.floor('h')
hour_counts = {}
for hour in df['hour']:
if hour in hour_counts:
hour_counts[hour] = hour_counts[hour] + 1
else:
hour_counts[hour] = 1
print hour_counts
count = Scatter(
x= hour_counts.keys,
y= hour_counts.values,
name = "Number of Riders",
line = dict(color = '#17BECF'),
opacity = 0.8)
data = [count]
layout = dict(
title='Time Series with Rangeslider',
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1d',
step='day',
stepmode='backward'),
dict(count=6,
label='6d',
step='day',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
)
)
fig = dict(data=data, layout=layout)
iplot(fig)
任何人都可以提供一些见解吗?如果这是一个愚蠢的问题,请道歉。我对python很新。谢谢!