import pandas as pd
import seaborn as sn
import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np
path = r'C:\Users\bossd\OneDrive\Документы\datarn.csv'
df = pd.read_csv(path)
path2 = r'C:\Users\bossd\OneDrive\Документы\pipirka.csv'
df2 = pd.read_csv(path2)
x = (df2.loc[df2['timestamp'].str.startswith('2015')])
y = df2['cnt']
plt.scatter(x,y)
plt.show()
我想用包含‘2015’作为x轴的日期和表示这一天自行车租赁的‘cnt’参数来构建一个散点图. 但在运行代码后,我收到以下错误
Cell In[47], line 14
12 x = (df2.loc[df2['timestamp'].str.startswith('2015')])
13 y = df2['cnt']
---> 14 plt.scatter(x,y)
15 plt.show()
17 display(df2)
...
File ~\venv\lib\site-packages\matplotlib\category.py:214, in UnitData.update(self, data)
212 # check if convertible to number:
213 convertible = True
--> 214 for val in OrderedDict.fromkeys(data):
215 # OrderedDict just iterates over unique values in data.
216 _api.check_isinstance((str, bytes), value=val)
217 if convertible:
218 # this will only be called so long as convertible is True.
TypeError: unhashable type: 'numpy.ndarray'
数据帧如下所示,其中包含时间戳作为日期,而不是这一天的自行车租赁量
# read the following sample data with
df2 = pd.read_html('https://stackoverflow.com/q/77090789/7758804')[0]
timestamp | cnt |
---|---|
2015-01-04 | 9234 |
2015-01-05 | 20372 |
2015-01-06 | 20613 |
2015-01-07 | 21064 |
2015-01-08 | 15601 |
2016-12-27 | 10842 |
2016-12-28 | 12428 |
2016-12-29 | 14052 |
2016-12-30 | 11566 |
2016-12-31 | 11424 |