在XYZV CSV文件中集成X和Y

huangapple go评论65阅读模式
英文:

Integration of X and Y in a XYZV csv file

问题

我正在处理一个项目,基本上在一个CSV文件中有X、Y、Z和电压维度。我希望将这个XYZV网格缩减为XYV网格,以制作一个2D图。这需要我取相同的每对X、Y并在不同的Z值下平均电压列。

即:

X    Y.   Z.  V
1.   0.   1.  10
1.   0.   1.5. 5
1.   0.   0.   1 
1.   1.   1.   1

变成:

X.   Y.   V.  
1.   0.   5.333
1.   1.   1

我应该如何在Python中使用pandas或csv读取CSV文件来实现这个目标?

英文:

I am working on a project which essentially has X,Y,Z,Voltage dimensions within a csv file. I am hoping to take this XYZV grid and reduce it to a XYV grid to make a 2D plot. This would require that I take every X,Y pair that is the same and average the Voltage column under different Z values.

i.e

X    Y.   Z.  V
1.   0.   1.  10
1.   0.   1.5. 5
1.   0.   0.   1 
1.   1.   1.   1

Becomes:

X.   Y.   V.  
1.   0.   5.333
1.   1.   1

How would I do this in python reading in a csv file either through pandas or csv?

答案1

得分: 1

IIUC,您可以尝试使用 groupby_mean

df.groupby(['X', 'Y'], as_index=False)['V'].mean()
     X    Y         V
0  1.0  0.0  5.333333
1  1.0  1.0  1.000000

要读取CSV文件,使用 pd.read_csv

英文:

IIUC, you can try groupby_mean:

>>> df.groupby(['X', 'Y'], as_index=False)['V'].mean()
     X    Y         V
0  1.0  0.0  5.333333
1  1.0  1.0  1.000000

To read a csv file, use pd.read_csv:

huangapple
  • 本文由 发表于 2023年4月7日 03:02:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952918.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定