【问题标题】:How to iterate a data frame for plotting using (row, column) specified values in python如何在python中使用(行,列)指定值迭代数据框以进行绘图
【发布时间】:2019-11-06 19:03:49
【问题描述】:

我正在尝试迭代数据框中的行以绘制特定值,使用这样的数据框(名为 autom)

  nombre  d7Li  erd7Li  d41K  erd41K  d87Rb  erd87Rb symb       color
qw      a     1     0.5     0     0.5      1      0.5    o           b
dr      a     2     0.4     9     0.4      2      0.4    <           g
ft      a     3     0.3     8     0.3      3      0.3    >           r
gy      a     4     0.5     7     0.5      4      0.5    v       color
hj      a     5     0.4     6     0.4      5      0.4    ^           m
kl      a     6     0.3     5     0.3      6      0.3    p           y
lp      a     7     0.5     4     0.5      7      0.5    s        peru
zx      a     8     0.4     3     0.4      8      0.4    x       olive
dc      a     9     0.3     2     0.3      9      0.3    o   cadetblue
fv      a     0     0.5     1     0.5      0      0.5    <  darkorchid
bg      a     1     0.4     2     0.4      1      0.4    >      indigo
hn      a     2     0.3     3     0.3      2      0.3    v        peru
mj      a     3     0.5     4     0.5      3      0.5    ^       olive
qz      a     4     0.4     5     0.4      4      0.4    p           b
wx      a     5     0.3     6     0.3      5      0.3    s           g
rv      a     6     0.2     7     0.2      6      0.2    x           r

我尝试了这种方法,但我无法访问字典中的值进行绘图

autom.itertuples() 中的行:

taco = row._asdict()
print(taco)

我希望字典的输出可以通过字典名称和键读取

【问题讨论】:

    标签: dataframe dictionary tuples iteration


    【解决方案1】:

    用这种方法解决了

    fig = plt.figure(figsize=[20,12])
    
    fig, axs = plt.subplots(2, 2, sharex='col', sharey='row',gridspec_kw={'hspace': 0, 'wspace': 0}) 
    
    #erase extra
    fig.delaxes(axs[1][1])
    #rb Li
    axs[0,0].axis(xmin=autom['7Li'].min()-2*autom['er7Li'].max(), xmax=autom['7Li'].max()+2*autom['er7Li'].max())
    axs[0,0].axis(ymin=autom['87Rb'].min()-2*autom['er87Rb'].max(), ymax=autom['87Rb'].max()+2*autom['er87Rb'].max())
    
    
    for index in autom.index:
    
    
       axs[0, 0].errorbar(autom.at[index,'7Li'],autom.at[index,'87Rb'], xerr=autom.at[index,'er7Li'], yerr=autom.at[index,'er87Rb'], 
       marker=autom.at[index,'symb'], mec='black',  c=autom.at[index,'colorea'], label=autom.at[index,'nombre'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2014-03-28
      • 2020-09-27
      • 1970-01-01
      相关资源
      最近更新 更多