I am working on to create a python automation program for Excel.
I wanted to divide the longitude based on the median number.
What I want to get data is :
JavaScript
x
8
1
1. get the median number of longitude from excel file,
2
3
2. separate longitude based on median number
4
ex) if median number > 91:
5
allocate above 91 longitude to 'A'
6
else:
7
allocate below 91 longitude to 'B'
8
Below is my code:
JavaScript
1
7
1
for i in range(2, maxRow+1):
2
country = sheet.cell(i,7).value
3
longitude = sheet.cell(i,6).value
4
median = np.median(longitude)
5
if country=="United States":
6
print("Unnited States" + str(longitude))
7
Below is the output from this code. output
above the output is show all longitude in United States. However, I want to filter only 1. filter median from all the longitude, 2. if median > longitude: allocate longitudes to ‘A’ else: allocate longitudes to ‘B’
Could anyone help me with this issue ?
Advertisement
Answer
JavaScript
1
7
1
for i in range(2, maxRow+1):
2
country = sheet.cell(i,7).value
3
longitude = sheet.cell(i,6).value
4
median = np.median(longitude)
5
if country=="United States" and int(longitude)>-91:
6
print("Unnited States" + str(longitude))
7