python - Python pandas:使用条件进行索引
问题描述
我需要画一条连接数据帧中两个点的线(在下表中,一条连接 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)
解决方案
干扰器解决了这个问题:
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)
推荐阅读
- java - 在从 Spring Rest 发送到 UI 之前屏蔽实体字段
- javascript - 如何让 node.js webscraper 定期检查端点的数据更新?
- c# - 将用逗号分隔的字符串 [] 数组解析为二维数组 C#
- javascript - 如何使用 Javasript 在没有 htmlFor 的情况下获取标签?
- sql - 如何在 where 子句中将部分索引用于计算的过滤条件?
- jquery - 如何避免 jquery 中的 n^n^n 复杂循环?
- python - 提取后反向打印字符串
- python - 3d 图中的特殊水平线
- javascript - 从字符串输入解析 DataType
- javascript - 隐藏空的行和列