Reputation: 1
I have a data frame and I want to add a column with values 0, 0.005, 0.010, 0.015...up to the length of the df, how do I proceed? thanks
Upvotes: 0
Views: 871
Reputation: 917
One way to get there would be with the numpy.arange
function:
import numpy as np
df['new_column'] = np.arange(0, (df.shape[0]*0.005), 0.005)
Upvotes: 0
Reputation: 26211
Only Pandas:
df = df.assign(newcol=pd.Series(range(df.shape[0])) * 0.005)
Using Numpy:
df = df.assign(newcol=np.arange(df.shape[0]) * 0.005)
Upvotes: 1