Oct-28-2020, 02:15 PM
I have many lines of data like:
[{'begins_at': '2020-10-22T14:00:00Z',
'open_price': '5.125000',
'close_price': '5.130000',
'high_price': '5.170000',
'low_price': '5.120000',
'volume': 134609,
'session': 'reg',
'interpolated': False,
'symbol': 'PSEC'},
{'begins_at': '2020-10-22T15:00:00Z',
'open_price': '5.135000',
'close_price': '5.140000',
'high_price': '5.150000',
'low_price': '5.130000',
'volume': 48897,
'session': 'reg',
'interpolated': False,
'symbol': 'PSEC'},
When I try to export this to csv using the following:
<blockquote class="imgur-embed-pub" lang="en" data-id="a/WldrlGx" data-context="false" ><a href="//imgur.com/a/WldrlGx"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
[{'begins_at': '2020-10-22T14:00:00Z',
'open_price': '5.125000',
'close_price': '5.130000',
'high_price': '5.170000',
'low_price': '5.120000',
'volume': 134609,
'session': 'reg',
'interpolated': False,
'symbol': 'PSEC'},
{'begins_at': '2020-10-22T15:00:00Z',
'open_price': '5.135000',
'close_price': '5.140000',
'high_price': '5.150000',
'low_price': '5.130000',
'volume': 48897,
'session': 'reg',
'interpolated': False,
'symbol': 'PSEC'},
When I try to export this to csv using the following:
import csv with open('twostocks.csv', 'w', newline='') as csvfile: fieldnames = [ 'begins_at', 'open_price', 'close_price', 'high_price', 'low_price', 'volume', 'session', 'interpolated', 'symbol' ] writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore') writer.writeheader() writer.writerows(data)the result yields all of the headers, but the only data output is a single cell containing just 'PSEC' below the 'symbol' column.
<blockquote class="imgur-embed-pub" lang="en" data-id="a/WldrlGx" data-context="false" ><a href="//imgur.com/a/WldrlGx"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>