SHARE
TWEET

Untitled

a guest Nov 6th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import psycopg2
  3.  
  4. time_range = [1980, 1985, 1990, 1995, 2000, 2005, 2010]
  5. countries = ['Germany', 'Austria', 'Italy', 'Switzerland', 'France', 'China']
  6.  
  7. conn = psycopg2.connect("dbname='...' user='...' host='localhost' password='...'")
  8.  
  9. for i in time_range:
  10.     for country in countries:
  11.         df = pd.read_sql("""
  12.         SELECT * from mytable
  13. #countries should appear in 'country', e.g. name_0 = 'Germany' in first iteration
  14. #years should appear in year, e.g. year >= 1980 and year <= 1984 in first iteration
  15.         WHERE name_0 = 'country' and year >= i  and year <= i+4;
  16.         """, con=conn)
  17.  
  18. #now clustering of data in df - code not shown
  19. #save resulting array as columns in csv-file using iterators from loop in file name,
  20. #e.g., data_Germany_1980.csv in first iteration
  21.         np.savetxt("data_country_i.csv", np.c_[a,b,c,d], delimiter=",", header="var1,var2,labels,probabilities", fmt='%1.4f', comments="")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top