yashul
yashul

Reputation: 101

Binning DataFrame based on index

I have a Pandas dataframe with 150 rows and columns "A","B","C". I want to create column "D" that must have:

How can I do this?

Upvotes: 2

Views: 68

Answers (1)

jpp
jpp

Reputation: 164783

Assuming your dataframe index is a regular pd.RangeIndex (i.e. 0, 1, 2, ...):

df['D'] = df.index // 50 + 1

Upvotes: 3

Related Questions