-1
lst = ['SymbolA','SymbolB', 'SymbolC' .... 'SymbolN']

I want to create dynamic Dataframe in Python Pandas.

for i in lst:
   data = SomeFunction(lst[i]) # This will return dataframe of 10 x 100

   lst[i]+str(i) = pd.DataFrame(data)

pd.Concat(SymbolA1,SymbolB1,SymbolC1,SymbolD1)

Anyone can help on how to create the dataframe dynamically to achieve as per the requirements?

Mohan Stocks
  • 13
  • 1
  • 4
  • Possible duplicate of [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – IanS Sep 19 '18 at 10:01
  • Why don't you directly do `pd.concat([pd.DataFrame(SomeFunction()) for i in lst])`? – IanS Sep 19 '18 at 10:02

2 Answers2

2

I hope this will help, as i understood from this.

gbl = globals()

lst = ['SymbolA','SymbolB', 'SymbolC' .... 'SymbolN']

for i in lst:

   data = SomeFunction(lst[i])

   gbl[lst[i]+str(i)] = pd.Dataframe(data)

this will create a df dynamically . for accessing those df you need to run code like this.

gbl[lst[i]+str(i)]

try this..

Sarath_Mj
  • 323
  • 1
  • 2
  • 14
0

You input has to be like below:

lst = ({'data':['SymbolA','SymbolB', 'SymbolC', 'SymbolN']})

print pd.DataFrame(lst)
Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
Vijay Lingam
  • 101
  • 4
  • datadf = SomeFunction(lst[i]) This will return some values of 10col and 100 rows as Dataframe and then this datadf will be added into final Dataframe. – Mohan Stocks Sep 19 '18 at 10:33