Python Forum
How to add a few empty rows into a pandas dataframe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: How to add a few empty rows into a pandas dataframe (/thread-21199.html)



How to add a few empty rows into a pandas dataframe - python_newbie09 - Sep-18-2019

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


RE: How to add a few empty rows into a pandas dataframe - scidam - Sep-19-2019

You don't need to iterate over all columns, just do something like this
df.reindex(df.index.tolist() + list(range(20, 40)))



RE: How to add a few empty rows into a pandas dataframe - python_newbie09 - Sep-20-2019

(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!