-1

I have a list (called temp) of DataFrames where I want to save each DataFrame in a unique JSON File and give the file the name as the string value in the DataFrame column 'symbol'.

My approach is:

temp[i].to_json(temp[i][[temp[i]['symbol']] + '.txt') for i in 
temp.symbol.unique()

But I get the following error:

SyntaxError: invalid syntax
Rafael
  • 7,002
  • 5
  • 43
  • 52
coding404
  • 15
  • 2
  • 5
  • if `temp` is a list of `DataFrames`, then it has no attribute `symbol`. You'll need to give more information about exactly what temp is, and what the properties of the `DataFrames` in it are. Do they all have one unique symbol, for instance, or can each one have a collection of symbols? – ALollz Mar 27 '18 at 19:08

1 Answers1

0

What do you mean by the string value in the column 'symbol'? The first row's value? If so, the solution is:

for df in temp: df.to_json(df.symbol.values[0] + '.txt')
n3utrino
  • 1,160
  • 1
  • 8
  • 16