Is there a way to subtract a constant value from the whole column?
If my dataframe is
I want to subtract 2.5 from column 1 so that it appears as
Also, is it possible to convert Date+Time into minutes?
Thank you!
Is there a way to subtract a constant value from the whole column?
If my dataframe is
I want to subtract 2.5 from column 1 so that it appears as
Also, is it possible to convert Date+Time into minutes?
Thank you!
If df
is your dataframe, simply use
df.Distance += 2.5
for adding a constant, or
df.Distance -= 2.5
for subtracting it.
(I'm not sure which one of them you want to do.)
using .apply is always a fast way to handle something like this
#data.csv is you data
import pandas as pd
df = pd.DataFrame.read_csv('data.csv')
#you want to perform this operation on column 1 that has a label 'A'
#make a function
def col_subtract(row):
row['A'] = row['A'] - 2.5
return row
#apply the function to the dataframe
df = df.apply(col_subtract, axis=1)
note: you could also just pass it a lambda function, I just felt it was cleaner to make a formal user defined function with a name to emphasize what you're doing.