1

I have a large DataFrame that contains a lot of stellar parameters from a range of sources for comparison. E.g. for stellar temperature I have anywhere between 1 and 6 results for a star in separate columns (eg. of table here: https://i.stack.imgur.com/LIGdZ.png). I want to collapse these columns to one 'Temperature' column which takes the GAIA_Teff preferably, then if that is not available then the V&F_Teff and so on. Is there a simple dataframe method that can do this or should I just use a bunch of if statements or similar?

Thanks

ebrown88
  • 11
  • 2
  • You may find the answers to this question: https://stackoverflow.com/questions/31828240/first-non-null-value-per-row-from-a-list-of-pandas-columns to be useful. – Juan Estevez Oct 02 '20 at 22:52

1 Answers1

0

I did this:

star_frame['Teff']=np.where(star_frame['GAIA_teff_val'].notnull(),star_frame['GAIA_teff_val'],
                        np.where(star_frame['V&F_Teff'].notnull(),star_frame['V&F_Teff'],
                                 np.where(star_frame['Pastel_Teff'].notnull(),star_frame['Pastel_Teff'],
                                          np.where(star_frame['Sim_Teff'].notnull(),star_frame['Sim_Teff'],
                                                   np.where(star_frame['Teff_from_HIP_BV'].notnull(),star_frame['Teff_from_HIP_BV'],
                                                            star_frame['Teff_from_Sim_BV'])))))
ebrown88
  • 11
  • 2