Reputation: 66
I have a dataset which have latitude and longitude values . I have separated them into even positions and odd positions.I want to consider if first even value must be taken with only the first value of odd.
But my for loop considers one value of even with all the value of odd and then does the save thing for all.
As I have return a function for the attribute cooords.
import pandas as pd
df=pd.read_csv("/home/even_odd.csv")
even=df[::2]
odd = df.iloc[1::2]
for row in even.itertuples(index=True, name='Pandas'):
lat1=getattr(row, "lat")
lng1=getattr(row, "lon")
for row in odd.itertuples(index=True, name='Pandas'):
lat2=getattr(row, "lat")
lng2=getattr(row, "lon")
print("/////-------------")
azimuth = calculateBearing(lat1,lng1,lat2,lng2)
azimuth
coords = main(interval,azimuth,lat1,lng1,lat2,lng2)
print(coords)
I want a for loop to consider the first value of even dataframe with only the the first value of odd dataframe and then so on.
Upvotes: 0
Views: 55
Reputation: 2331
you can try to loop through odd and even simultaneously:
for (rowEven, rowOdd) in zip (even.itertuples(index=True, name='Pandas'), odd.itertuples(index=True, name='Pandas')):
# do additional works
lat1=getattr(rowEven, "lat")
lng1=getattr(rowEven, "lon")
lat2=getattr(rowOdd, "lat")
lng2=getattr(rowOdd, "lon")
Upvotes: 3