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

Adding extra n rows at the end of a dataframe of a certain value

I have a dataframe with currently 22 rows

index value
  0     23
  1     22
  2     19
 ...
 21     20

to this dataframe, i want to add 72 rows to make the dataframe exactly 100 rows. So i need to fill loc[22:99] but with a certain value, let’s say 100.

I tried something like this

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

uncon_dstn_2021['balance'].loc[22:99] = 100

but did not work. Any idea?

>Solution :

You can do reindex

out = df.reindex(df.index.tolist() + list(range(22, 99+1)), fill_value = 100)
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