loops - looping the data using date variable in python -


i have following dataframe datetime, lon , lat variables. data collected each second means each date repeated 60 times

i doing calculations using lat, lon values , @ end need write data postgres table.

2016-07-27 06:43:45    50.62    3.15 2016-07-27 06:43:46    50.67    3.22 2016-07-28 07:23:45    52.32    3.34 2016-07-28 07:24:46    52.67    3.45 

currently have 10 million records . taking longer time if use whole dataframe computing.

how can loop each date, write db , clear dataframe??

i have converted datetime variable date format

df['date'] = df['datetime'].dt.date df = df.sort(['datetime'])  computation df.loc[(df['lat'] > 50.10) & (df['lat'] <= 50.62), 'var1'] = 1 df.loc[(df['lan'] > 3.00) & (df['lan'] <= 3.20), 'var2'] = 1 

writing db

df.to_sql('table1', engine,if_exists = "replace",index = false) 

have considered using groupby() function? can use treat each 'date' seperate dataframe , run computations.

for sub_df in df.groupby('date'):     # computations 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -