Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Incremental column coming from variable in pandas

I have a variable that comes from a function that returns an integer.

I need to create an incremental column in my dataframe from this integer, how can I do that?

Integer example: 201

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output expected:

Stores New column
Marcos Store 202
Lais Store 203
Carol Store 204
Ana Store 205
Maria Store 206

>Solution :

n = 201
df['New column'] = df.index + n + 1

Output:

         Stores  New column
0  Marcos Store         202
1    Lais Store         203
2   Carol Store         204
3     Ana Store         205
4   Maria Store         206
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading