Python:循环的多个图形

velaa5lx  于 2023-05-27  发布在  Python
关注(0)|答案(1)|浏览(91)

我的数据集有5个ClientID,我想为每个ClientID生成一个图表
我已经能够遍历我的键并创建五个图,但是,它们包括所有数据,而不仅仅是客户端ID的数据

# group by "X" column
clients = dfT1.groupby('ClientID')
 
# extract keys from groups
keys = clients.groups.keys()

for i in keys:
    dfT1[:].plot(x='Dates', y=['DWLTActual', 'Weight'], figsize=(10,5), grid=True)
    plt.show()

输出量
Example of the 5 graphs
预期输出
Example of one of the client graphs

disho6za

disho6za1#

你能像这样检查一下吗。我在我的计算机上本地执行了示例数据,它工作了。
在打印之前,需要首先过滤客户端数据。

clients = dfT1.groupby('ClientID')

# Extract keys from groups
keys = clients.groups.keys()

for client_id in keys:
    # Filter data for the current client ID
    client_data = clients.get_group(client_id)

    # Plot the filtered data
    client_data.plot(x='Dates', y=['DWLTActual', 'Weight'], figsize=(10, 5), grid=True)

    # Set the title of the graph as the ClientID
    plt.title('ClientID: {}'.format(client_id))

    # Show the plot
    plt.show()

相关问题