数据框的面积积

问题描述 投票:1回答:1

我有以下数据框:

Dataframe

它包含一个时间戳作为DF和两列,其中第一列descriebes风向(S =南方,SE =东南亚等)的索引。第二列descriebs时间戳期间百分数的。例如。东南与87.5%,与南方12.5%一整日(2018年2月21日)期间。

区域地块应形象化的每一天每一个方向的百分比。与在x轴和Y轴加起来总共100%的百分比天。

我不知道如何让我的当前DF到一个我需要能够想象我期望的图形。

有任何想法吗?

时间戳仍然需要索引,但我需要为每一个可能Winddirection列。然后该柱应包含用于特定风向的每个时间步长的precantage。

这是只为北,东,南,西方向的超级抽象绘画。

enter image description here

python pandas visualization
1个回答
3
投票

首先,您需要.pivot,然后你可以绘制。

Sample Data

import pandas as pd
df = pd.DataFrame({'date': pd.to_datetime(['2018-02-21', '2018-02-21', 
                                           '2018-02-22', '2018-02-22', '2018-02-22', 
                                           '2018-02-23', '2018-02-23']),
                   'direction': ['SE', 'S', 'SE', 'E', 'S', 'E', 'SE'],
                   'pct': [87.5, 12.5, 75, 20.8333333, 4.166667, 54.1557, 45.8333]})

Code

df.pivot(index='date', columns='direction', values='pct').fillna(0).plot(kind='area')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.