我有看起來像這樣的資料:
file | timestamps
1 | 02/01/1970
1 | 03/01/1970
1 | 04/01/1970
1 | 05/01/1970
2 | 06/01/1970
2 | 07/01/1970
3 | 08/01/1970
3 | 09/01/1970
3 | 10/01/1970
在 x 軸上,我希望每個file. 在 y 軸上,我想要timestamps. 它應該看起來類似于這個情節,但我不知道如何得到這個情節。這是瀑布圖嗎?

uj5u.com熱心網友回復:
資料不多,但這是您示例的結果
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import pandas as pd
data = [[1, '02/01/1970'],
[1, '03/01/1970'],
[1, '04/01/1970'],
[1, '05/01/1970'],
[2, '06/01/1970'],
[2, '07/01/1970'],
[3, '08/01/1970'],
[3, '09/01/1970'],
[3, '10/01/1970']]
df = pd.DataFrame(data, columns = ['file', 'timestamps'])
df['timestamps'] = pd.to_datetime(df['timestamps'], format = '%d/%m/%Y')
tot_delta_d = 0
tot_file = 0
fig, ax = plt.subplots()
for f in df['file'].unique():
delta_d = df[df['file'] == f]['timestamps'].max() - df[df['file'] == f]['timestamps'].min()
rect = patches.Rectangle((tot_delta_d, tot_file),
delta_d.days,
df[df['file'] == f].shape[0],
color='indigo')
ax.add_patch(rect)
tot_delta_d = delta_d.days
tot_file = df[df['file'] == f].shape[0]
plt.xlim([0, tot_delta_d])
plt.ylim([0, tot_file])
ax.set_xlabel('Parquets')
ax.set_ylabel('Timestamps')
ax.invert_yaxis()
plt.show()
輸出 :

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/383042.html
標籤:Python 熊猫 matplotlib 阴谋
上一篇:合并資料幀熊貓中的所有txt檔案
