data = data.iloc[:10, :]改成取后10行
时间: 2024-01-13 09:04:37 浏览: 76
要取后10行数据,可以使用 `data.iloc[-10:, :]`,其中 `-10:` 表示从倒数第10行开始,一直到最后一行。完整的代码如下:
```
select_sqli ="SELECT time,SUM(CASE WHEN type_c='两厢车' THEN xiaoliang ELSE 0 END)/SUM(xiaoliang) AS ratio,1 - SUM(CASE WHEN type_c='两厢车' THEN xiaoliang ELSE 0 END)/SUM(xiaoliang) AS ratio_complement FROM sheji.sale GROUP BY time;"
cur.execute(select_sqli)
data = pd.DataFrame(cur.fetchall(), columns=['time', 'portion','r_portion'])
data = data.set_index('time')
data = data.sort_index(ascending=False)
data = data.iloc[-10:, :] # 取后10行数据
plt.figure(figsize=(9.42,1))
data.plot(kind='bar', stacked=True, x='time')
plt.title('Sales Ratio of Different Categories')
plt.xlabel('Category')
plt.ylabel('Ratio')
plt.xticks(rotation=90)
plt.savefig('portion.png',dpi=300)
pix = QPixmap("portion.png")
new_width = self.Market.label_4.width()
new_height = int(pix.height() * new_width / pix.width())
scaled_pixmap = pix.scaled(QSize(new_width, new_height), Qt.AspectRatioMode.KeepAspectRatio,Qt.TransformationMode.SmoothTransformation)
self.Market.label_4.setPixmap(scaled_pixmap)
plt.close()
```
这样就可以取后10行数据了。
阅读全文