Skip to content

Instantly share code, notes, and snippets.

@davidzhaodz
Last active December 16, 2020 04:30
Show Gist options
  • Save davidzhaodz/374c60ec4b6094ad131f031dd5b96656 to your computer and use it in GitHub Desktop.
Save davidzhaodz/374c60ec4b6094ad131f031dd5b96656 to your computer and use it in GitHub Desktop.
#create dataframe from lists
df = pd.DataFrame(
{'time': [datetime.strptime(x,"%Y-%m-%dT%H:%M:%S.%fZ") for x in time], #formatting our timestamp
'open': [float(x.strip('0')) for x in open], #removing trailing 0's and converting to float
'high': [float(x.strip('0')) for x in high],
'low': [float(x.strip('0')) for x in low],
'close': [float(x.strip('0')) for x in close],
'vol': [float(x.strip('0')) for x in vol]
})
#create dictionary from dataframe
df_dict = df.to_dict('records')
#df_dict should look something like this
#[{'close': 19269.58,
# 'high': 19279.54,
# 'low': 19269.58,
# 'open': 19277.78,
# 'time': Timestamp('2020-12-15 11:42:00'),
# 'vol': 8.04629723},
# {'close': 19280.0,
# 'high': 19280.0,
# 'low': 19269.5,
# 'open': 19269.5,
# 'time': Timestamp('2020-12-15 11:43:00'),
# 'vol': 4.75698706},
#........................
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment