I have a pandas dataframe from a csv file and i want to add 3 columns in python 3.8
add a column and convert meters to miles (length is meters, new column will be length_miles).
add column to convert meters to feet (elevation_gain is in meters, new column will be elevation_gain_feet.
add a column that computes a difficulty rating as follows: nps difficulty rating = Elevation Gain(feet) x 2 x distance (in miles). The product's square root is the numerical rating.
This needs to be broken down a little further into a difficulty rating of 1-5. the current difficulty rating in the data set is not informative so i want to use the national park service rating.
if the numerical difficulty rating is:
under 50, then the value is 1 50-100, then difficulty rating is 2 101-150, then difficulty rating is 3 151-200, then difficulty rating is 4 above 200, then difficulty rating is 5
Ideally this would compute and just put the number 1-5 in the column, but having 2 new columns for #3 would be fine as well.
Here are the columns from my dataframe and values from a couple rows. I have not yet thought about making the nps 1-5 ratings in the dataframe, I am not sure if I can, or need to do it outside the dataframe in a function.
unfortunately it does not seem to be adding the columns like I want it to, so I think I must be doing something wrong.
code I have so far
df = pd.read_csv('data.csv')
df.assign(length_miles = lambda x: x['length'] * 0.00062137, axis = 1)
df.assign(elevation_gain_ft = lambda x: x['elevation_gain'] * 3.28084, axis = 1)
df.assign(num_dif_rating = lambda x: np.sqrt( x['length_miles'] * 2 * x['elevation_gain_ft'], axis = 1))