0

I have 3 columns in my dataframe, date time and snowfall. The snowfall data needs transforming from kg m-3 s-1 to mm/day. To do this, I divide by the density of snow and multiply by seconds in the day. (n/70)*86400

I would like to do this by overwriting the the snowfall column in the dataframe with the calculation for plotting.

I have the loop function which transforms the values but will not append the result to the list (which is the basic version of what I was looking for), but ideally I would like to have it simply overwrite the column in the dataframe for ease of plotting.

def snowfallconverter(in1):
    snowfall_fix = []
    for ii in in1:
        snowfall_mm = (ii/70)*8600
        snowfall_fix.append(snowfall_mm)

The dataset looks like:

date       time     snowfall
01/11/2017 12:00:00 -4.43e-06
02/11/2017 12:00:00 -9.04e-08

Thank you in advance.

1 Answer 1

1

Loop here is not necessary, divide and multiple column by scalars only:

df['snowfall_mm'] = df['snowfall'] / 70 * 8600
print (df)
         date      time      snowfall  snowfall_mm
0  01/11/2017  12:00:00 -4.430000e-06    -0.000544
1  02/11/2017  12:00:00 -9.040000e-08    -0.000011

Or overwrite same column:

df['snowfall'] = df['snowfall'] / 70 * 8600
print (df)
        date      time  snowfall
0  01/11/2017  12:00:00 -0.000544
1  02/11/2017  12:00:00 -0.000011
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.