You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
There should be an option to reshape the photometry table so that the bands are columns.
For example:
txt = 'SELECT * FROM photometry WHERE source_id=700'
t = db.query(txt, fmt='table')
df = t.to_pandas()
df_new = df.pivot(index='source_id', columns='band', values='magnitude')
This has df_new with each band as a column name and the band magnitudes as the column values.
The text was updated successfully, but these errors were encountered:
dr-rodriguez
changed the title
Reshape/pivot magnitudes
Option to reshape/pivot photometry table
Mar 4, 2016
Here's an example for when you have multiple magnitudes for a particular band:
txt = 'SELECT p.source_id, p.band, p.magnitude FROM photometry AS p JOIN sources AS s WHERE p.source_id=s.id'
t = db.query(txt, fmt='table')
df = t.to_pandas()
df2 = df.convert_objects(convert_numeric=True)
pd.pivot_table(df2, values='p.magnitude', index=['p.source_id'], columns=['p.band'], aggfunc=np.mean)
Indeed, a view would be the easiest to implement and I would favor that at the moment, though it requires the database administrator to know how to do that instead of being a built-in method.
For my tests I took the average of any multiple entries, but I'm not sure how one would preserve multiple entries per source. I would guess that if you have multiple epoch as more of a timeseries then either these should not be pivoted or they should be grouped by date/time but only for a single source.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
There should be an option to reshape the photometry table so that the bands are columns.
For example:
txt = 'SELECT * FROM photometry WHERE source_id=700'
t = db.query(txt, fmt='table')
df = t.to_pandas()
df_new = df.pivot(index='source_id', columns='band', values='magnitude')
This has df_new with each band as a column name and the band magnitudes as the column values.
The text was updated successfully, but these errors were encountered: