Created
April 21, 2016 21:19
-
-
Save petigura/a677c99403c93c54217c03b70a566ac1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from cStringIO import StringIO as sio # Let's us treat strings like files | |
| spex = """\ | |
| epic,teff,uteff | |
| 100000000,5000,100 | |
| 200000000,4000,100 | |
| """ | |
| specmatch = """\ | |
| epic,teff,uteff | |
| 100000000,5050,70 | |
| 300000000,6000,70 | |
| """ | |
| catalog = """\ | |
| epic,k2_camp | |
| 100000000,C1 | |
| 200000000,C2 | |
| 300000000,C3 | |
| """ | |
| # would normally read in as | |
| # specmatch = pd.read_csv(<path to file>) | |
| specmatch = pd.read_csv(sio(specmatch)) | |
| spex = pd.read_csv(sio(spex)) | |
| catalog = pd.read_csv(sio(catalog)) | |
| print "individual tables" | |
| print specmatch | |
| print spex | |
| print catalog | |
| merged = pd.merge( | |
| specmatch, # left table | |
| spex, # right table | |
| on=['epic'], # join column(s) | |
| suffixes=['_specmatch','_spex'], # how to treat duplicate colums | |
| how='outer', # join method | |
| ) | |
| print "joined table. row for every star in the union of both lists" | |
| print merged | |
| merged = pd.merge(merged, catalog, on=['epic']) | |
| print "merging in campaign id" | |
| print merged | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment