如何以CSV格式输出数据

问题描述 投票:0回答:1

我正在尝试编写一个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的好方法?

python csv export
1个回答
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')
© www.soinside.com 2019 - 2024. All rights reserved.