I have defined a function as shown.
def calculate_mass_loss(group, idnum):
"""
Calculates mass loss on star referenced by idnum due to high mass stars
Parameters
----------
group: `pd.DataFrame`
Dataframe of all stars
idnum: int
ID number of star we care about
Returns
-------
mass_loss: float
Disc mass loss in solar masses per year
"""
#this will select just the low-mass star I'm focussing on
my_star = group.query(f'ID == {idnum}')
# this will select just the high mass stars
high_mass_stars = group.query('star_mass > 3')
# use a function to calculate a separation column
high_mass_stars['separation'] = calc_separation(high_mass_stars, my_star)
high_mass_stars['flux_FUV'] = high_mass_stars['LFUV'] / (4*np.pi*high_mass_stars['separation']**2) /(1.6*10**(-3))
total_fuv_flux = high_mass_stars.loc[:, ('flux_FUV')].sum()
# use interpolation function to calculate mass loss
mass_loss = find_mass_loss(total_fuv_flux, my_star)
return(mass_loss)
calculate_mass_loss(snap_0, 2)
However, when I run the code I get an error that I don't understand:
<ipython-input-11-733debcada29>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
high_mass_stars['separation'] = calc_separation(high_mass_stars, my_star)
<ipython-input-11-733debcada29>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
high_mass_stars['flux_FUV'] = high_mass_stars.loc[:, ('LFUV')] / (4*np.pi*high_mass_stars.loc[:, ('separation')]**2) /(1.6*10**(-3))
I was wondering if anyone could explain it and potentially tell me how to fix it please???