【问题标题】:Python pandas: Indexing using a conditionPython pandas:使用条件进行索引
【发布时间】:2019-10-07 20:18:08
【问题描述】:

我需要画一条连接数据框中两个点的线(在下表中,一条连接 S01 到 S02、S01 到 S04、S03 到 S04 等的线)点不能明确定义,而是通过迭代数据框。每行中的坐标是“到”点的坐标。

这是我迄今为止尝试过的:

df = pd.read_csv(1234.csv')

for index, row in df.iterrows():
    x_coords = [df.loc["from", "x"], df.loc["to", "x"]]
    y_coords = [df.loc["from", "y"], df.loc["to", "y"]]
    plt.plot(x_coords, y_coords,'grey', linewidth=0.5)

【问题讨论】:

  • 邮政编码和数据,而不是代码/数据的图像

标签: python pandas dataframe indexing


【解决方案1】:

干扰器解决了:

for i in df.index:
   df.set_index('to')
   a = df.at[i,'From'] #row of from value
   b = a - 1 #correct index value of row
   ax = df.at[b, 'x'] #x value of from
   ay = df.at[b, 'y'] #y of from
   plt.plot([ax,df.at[i,'x']],[ay,df.at[i,'y']],'grey', linewidth=0.5)

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 2017-12-03
    • 2020-01-02
    • 2021-07-14
    • 2016-01-15
    • 2022-01-18
    • 2019-07-29
    • 2018-11-22
    相关资源
    最近更新 更多