Bottom Page

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
Quote
#2
You don't need to iterate over all columns, just do something like this
df.reindex(df.index.tolist() + list(range(20, 40)))
Quote
#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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Obtaining Correct Date In Pandas DataFrame eddywinch82 7 386 Yesterday, 04:47 PM
Last Post: sandeep_ganga
  Parse XML String in Pandas Dataframe creedX 2 282 Dec-09-2019, 07:35 PM
Last Post: creedX
  Pandas dataframe to join three tables using like condition among them sandeep_ganga 0 237 Nov-29-2019, 08:30 AM
Last Post: sandeep_ganga
  Pandas Dataframe to Google Big Query Ecniv 2 883 Nov-21-2019, 02:26 PM
Last Post: Ecniv
  manipulating a dataframe - pandas nsx200 2 217 Nov-14-2019, 10:38 AM
Last Post: nsx200
  Pandas dataframe columns collapsed in Spyder when printing UniKlixX 2 218 Nov-04-2019, 07:00 AM
Last Post: UniKlixX
  pandas dataframe iloc mystery edvvardbrian 2 300 Oct-29-2019, 02:55 PM
Last Post: jefsummers
  delete rows with empty strings in Series ilcaa72 1 759 Oct-04-2019, 05:34 PM
Last Post: ichabod801
  Dropping a column from pandas dataframe marco_ita 6 1,639 Sep-07-2019, 08:36 AM
Last Post: marco_ita
  created a pandas series instead of pandas DataFrame ibaad1406 6 779 Sep-06-2019, 06:23 AM
Last Post: ibaad1406

Forum Jump:


Users browsing this thread: 1 Guest(s)