我有以下資料框 [1],其中包含與音樂收聽有關的資訊。我想列印如下
我用來獲取情節的代碼如下:
import numpy as np
import pylab as pl
from matplotlib import collections as mc
lines = [ [(2, 107), (3,107)], [(11,133),(12,133)], [(12,122),(13,122)], ]
c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)])
lc = mc.LineCollection(lines, colors=c, linewidths=2)
fig, ax = pl.subplots()
ax.add_collection(lc)
ax.autoscale()
ax.margins(0.1)
獲取資料:
import numpy as np
import pandas as pd
dfLunedi = pd.read_csv( "5.sab.csv", encoding = "ISO-8859-1", sep = ';')
dfSlotMean = dfLunedi.groupby('slotID', as_index=False).agg( NSabUn=('date', 'nunique'),NSabTot = ('date', 'count'), MeanBPM=('tempo', 'mean') )
df = pd.DataFrame(dfSlotMean)
df.to_csv('sil.csv', sep = ';', index=False)
df.drop(df[df.NSabUn < 3].index, inplace=True)
uj5u.com熱心網友回復:
您可以遍歷行并像這樣繪制每個段:
for _, r in df.iterrows():
plt.plot([r['slotID'], r['slotID'] 1], [r['MeanBPM']]*2)
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/438499.html
標籤:Python 熊猫 数据框 matplotlib
