![](/img/trans.png)
[英]For all the unique 'words" of a column, the find unique cells from another column , then average corresponding values of another column in python
[英]Extract and manipulate data from csv - finding unique values and displaying corresponding data from another column
我有一个看起来像这样的 csv:
A栏 | B栏 |
---|---|
192.168.10.1 | 文本 A |
192.168.10.1 | 文本 B |
192.168.10.1 | 文字 C |
192.168.10.2 | 文本 A |
192.168.10.3 | 文本 B |
192.168.10.3 | 文字 C |
192.168.10.4 | 文本 A |
192.168.10.4 | 文字 C |
预期的结果是:
A栏 | B栏 |
---|---|
文本 A | 192.168.10.1 |
192.168.10.2 | |
192.168.10.4 | |
文本 B | 192.168.10.1 |
192.168.10.3 | |
文字 C | 192.168.10.1 |
192.168.10.3 | |
192.168.10.4 |
这可能是 Excel 中的某些东西,或者理想情况下我可以使用 python(熊猫)做的事情?
非常感谢任何善意的回应,
为此,您可以简单地使用 pandas 的 groupby function。 将 csv 读入 python 作为 dataframe 后,可以运行以下命令:
final = df.groupby(['Column B'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.