如何以CSV格式输出数据

时间:2017-12-24 17:52:22

标签: python csv export

我正在尝试编写一个python脚本,我可以使用该脚本从Binance中提取余额并定期将其导出为CSV。我有我的API调用设置来使用this获取余额,输出如下所示:

u'ARK': {'locked': u'0.00000000', 'free': u'0.56748500'}, u'ARN': {'locked': u'0.00000000', 'free': u'0.06450000'}}.

什么是将这一切分开并将其变为CSV的好方法?

1 个答案:

答案 0 :(得分:1)

你有没有尝试过熊猫?

import pandas as pd

# get some output as a dictionary. i got this from the link you provided
dict_to_output = {u'123456': {'ask': u'0.00000000',
  'askQty': u'0.00000000',
  'bid': u'0.00000000',
  'bidQty': u'0.00000000'},
 u'ASTBTC': {'ask': u'0.00005149',
  'askQty': u'3396.00000000',
  'bid': u'0.00004951',
  'bidQty': u'222.00000000'}}

# load the output into pandas dataframe
 df_to_output = pd.DataFrame(dict_to_output)

# output the file
 df_to_output.to_csv(r'C:\Users\fffrost\Desktop\output.csv')
相关问题