'How do I get specific columns with the same name from a csv file in Python
I hope you can help me solve this problem guys.
This is the csv file (it goes down to over 4200 columns)

I need to get ALL the "electromotor_rpm"s with the associated values and units and then save it to a list. Afterwards I want to create a new csv file to analyze it and get the max, min and median from that data.
The file is very large, so there could be 200 "electromotor_rpm" columns.
I tried different approaches but couldn't find anything that could help me finally.
Solution 1:[1]
I found a solution:
import csv
import statistics
from csv import DictReader
el_list = []
electromotor_rpm_list = []
electromotor_rpm_stat = []
f = open('MAN.csv', "r", newline='')
werte_csv = csv.DictReader(f, delimiter=';')
for line in werte_csv:
ausgabe = f"{line['name']}: {line['value']} {line['unit']}"
if (line['name'] == 'electromotor_rpm'):
electromotor_rpm_list.append(float(line['value']))
print(electromotor_rpm_list)
electromotor_rpm_stat.append(statistics.mean(electromotor_rpm_list))
electromotor_rpm_stat.append(max(electromotor_rpm_list))
electromotor_rpm_stat.append(min(electromotor_rpm_list))
electromotor_rpm_stat.append(max(electromotor_rpm_list)-
min(electromotor_rpm_list))
print(statistics.mean(electromotor_rpm_list))
print(electromotor_rpm_stat)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hen Ma |
