-2

I would like to generate an Empty Dataframe and then adding a list as a new column with header to this DataFrame, I have such a code:

#define an empty dataframe
df()

start=0
for row in list1:
  blist=list()
  for data in list2:
    blist.append(data.Ordertype[0:row._c1]) 

  start=start + row._c1   
  #I would like to append blist now to  dataframe df() in this line

How can I do that? Do you have any Idea?

Scott Boston
  • 147,308
  • 15
  • 139
  • 187
Kaja
  • 2,962
  • 18
  • 63
  • 99
  • This is not how spark DataFrames are designed. Can you provide a [mcve] that explains in much more detail what your desired output is? There's likely a better way as this seems like an [XY problem](http://www.xyproblem.info). – pault Aug 14 '19 at 17:47
  • I got my answer :) – Kaja Aug 14 '19 at 17:50
  • If the accepted answer solves your problem, then this has nothing to do with pyspark or databricks. I'm removing those tags. – pault Aug 14 '19 at 17:51
  • Possible duplicate of [Append column to pandas dataframe](https://stackoverflow.com/questions/20602947/append-column-to-pandas-dataframe) – Håken Lid Aug 14 '19 at 22:48

1 Answers1

0
import pandas as pd
df = pd.DataFrame()

start=0
for row in list1:
  blist=list()
  for data in list2:
    blist.append(data.Ordertype[0:row._c1]) 

  start=start + row._c1  
   df['col_name_iteration'] = pd.Series(blist) 
Poojan
  • 3,366
  • 2
  • 17
  • 33