gpt4 book ai didi

python - 绘制 DataFrame 字典

转载 作者:行者123 更新时间:2023-12-03 14:50:49 25 4
gpt4 key购买 nike

我有一个 dictionaryDataFrames我想用于绘图。这是数据的示例:

import pandas as pd
import numpy as np

np.random.seed(5)
first = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3), index=range(1,4))
second = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)+0.2, index=range(1,4))
third = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)+0.05, index=range(1,4))
fourth= pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)-0.2, index=range(1,4))

d={'frame_1':first,'frame_2':second,'frame_3':third,'frame_4':fourth}

#This is what it looks like
d
{'frame_1': 1 2 3
1 0.221993 0.870732 0.206719
2 0.918611 0.488411 0.611744
3 0.765908 0.518418 0.296801, 'frame_2': 1 2 3
1 0.387721 0.280741 0.938440
2 0.641309 0.358310 1.079937
3 0.474086 0.614235 0.496080, 'frame_3': 1 2 3
1 0.678788 0.629838 0.649929
2 0.315819 0.334686 0.303588
3 0.377564 0.194164 0.215613, 'frame_4': 1 2 3
1 0.763931 0.760227 -0.011585
2 -0.175693 0.004556 0.499844
3 0.579515 -0.177067 0.377663}

最终,我想要 9 个单独的图表,这些图表绘制了 DataFrame 中每个元素组合的演变情况。 (11,12,13,..) 以 1,2,3,4(与“frame_1”、“frame_2”等相关)为 x 轴。需要明确的是,这意味着第一个图(与 11 相关)应包含值 0.221993、0.387721、0.678788 和 0.763931。

通常我总是解释我自己试图解决的问题。但是,在这种情况下,我对可能的解决方案一无所知。

注意:实际数据集为 10x10 DataFramesdictionary包含 75 个这样的数据帧,所以我更喜欢尽可能多的自动化。

最佳答案

我不确定我是否理解您想要的结果,但是:

for k in d:
ax = d[k].plot()
给出:
enter image description here
enter image description here
enter image description here

关于python - 绘制 DataFrame 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33166414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com