I have a dataframe that looks like this:
ID Zones Distance
E18 A 0.51
E22 A 3.92
E23 A 1.05
E26 A 0.675
E27 A 2.12
E18 B 0.51
E22 B 3.92
E23 C 1.05
E26 C 0.675
What I would like to do is to find the maximum value per interval.
So for example, for the zone "A" the maximum "Distance" is 3.92
and so on for all the "Zones"
I came up with the following loop to subdivide the dataframe into separate "Zones" as a dictionary:
csv_file=new_path+"distance"+".csv"
distance=pd.read_csv(csv_file, error_bad_lines=False)
distance_by_zones={}
zones=['A', 'B', 'C', 'D', 'D']
for i in range(len(zones)):
distance_by_zones[i]=distance.loc[distance["Zones"].isin([zones[i]])]
This code perfectly subdivides the dataframe into different bunches per each "Zones", for example:
print(distance_by_zones[2])
Unnamed: 0 ID Zones Distance
10 E18 C 0.57
11 E22 C 4.20
12 E23 C 1.13
13 E26 C 0.91
14 E27 C 2.43
What I need to do now, is to calculate the max distance in each of the "Zones". So, for example the output would be: max_distance_C=4.20
It would be great if the this operation is performed in the for loop
above, so I can manipulate the data in a one go...