0

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

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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)

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.