Skip to content
Advertisement

Set indices without manually typing them (too many), regular numerical sequences as indices

I have a pandas dataframe with 1111 rows and want to reindex the rows having the following names:

First 11 rows:

JavaScript

Next 100 rows:

JavaScript

next 1000 rows:

JavaScript

Additionally, for the last 900 rows, I need the block above, substituting the first 1s (1s after the p) with 2s, next block with 3s, next block with 4s, …, last block with 10s. Doing this manually will take a long time and I’m not sure how I can code this, any ideas?

Advertisement

Answer

You can easily build your blocks with comprehensions:

First 11 rows:

JavaScript

Next 100 rows:

JavaScript

Next 1000 rows:

JavaScript

Your final list is then lst1 + lst2 + lst3.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement