Python Forum
How to add a few empty rows into a pandas dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add a few empty rows into a pandas dataframe
#1
Hi, so far the examples I have found seems to only add 1 empty row to an existing dataframe but what if I have a specified number of empty rows that I want to add to a dataframe, how can this be done?

I tried the approach below:

for col in df.columns:
    df.reindex(df.index.values.tolist()+100)
but i am getting the error below:

TypeError: can only concatenate list (not "int") to list
Reply
#2
You don't need to iterate over all columns, just do something like this
df.reindex(df.index.tolist() + list(range(20, 40)))
Reply
#3
(Sep-19-2019, 01:37 AM)scidam Wrote: You don't need to iterate over all columns, just do something like this
df.reindex(df.index.tolist() + list(range(20, 40)))

thanks, this worked!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Formatting cells of a pandas dataframe into an OpenDocument ods spreadsheet Calab 1 603 Mar-01-2025, 04:51 AM
Last Post: Calab
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,069 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,584 Aug-26-2024, 04:52 PM
Last Post: Calab
  Loop over dataframe to fill in missing rows Scott 9 3,631 Jul-12-2024, 05:54 AM
Last Post: Scott
  Add NER output to pandas dataframe dg3000 0 1,128 Apr-22-2024, 08:14 PM
Last Post: dg3000
  HTML Decoder pandas dataframe column mbrown009 3 2,600 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,978 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 2,055 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 3,376 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,885 Jan-30-2022, 10:21 AM
Last Post: anto5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020