我希望我做得对。我是第一次登海报。 我有一个csv数据帧问题,几天来一直在寻找解决方案。这可能是一个小而明显的错误,但我试过一些例子。这是我的密码:
print('__Trades__' '\n')
since = int(time.time()*1000)-24*60*60*1000
xbtzartrades = c.list_trades(pair='XBTZAR', since=since)
exctrades = (xbtzartrades)
json_object = json.dumps(exctrades, indent=4) # Serializing json
with open("exdata/json/xbtzartrades.json", "w") as outfile: # Open a file in exdata/json/
outfile.write(json_object) # Writing to json
df = pd.read_json("exdata/json/xbtzartrades.json") # read the json file
df.to_csv(r'exdata/csv/xbtzartrades.csv', index=None)
# print(df) # Print the contents of df
# print(xbtzartrades) # Print the recent trades.
输出到exdata/json/xbtzartrades.json:
{
"trades": [
{
"sequence": 7933159,
"timestamp": 1586191458641,
"price": "139449.00",
"volume": "0.001444",
"is_buy": false
},
{
"sequence": 7933158,
"timestamp": 1586191450810,
"price": "139449.00",
"volume": "0.001122",
"is_buy": false
}, ------------> ECT.
而不是表格格式。CSV文件的结尾如下所示:
trades
"{'sequence': 7933159, 'timestamp': 1586191458641, 'price': '139449.00', 'volume': '0.001444', 'is_buy': False}"
"{'sequence': 7933158, 'timestamp': 1586191450810, 'price': '139449.00', 'volume': '0.001122', 'is_buy': False}"
"{'sequence': 7933157, 'timestamp': 1586191450695, 'price': '139449.00', 'volume': '0.003657', 'is_buy': False}"
"{'sequence': 7933156, 'timestamp': 1586191446474, 'price': '139450.00', 'volume': '0.004181', 'is_buy': True}"
"{'sequence': 7933155, 'timestamp': 1586191438571, 'price': '139449.00', 'volume': '0.005716', 'is_buy': False}"
"{'sequence': 7933154, 'timestamp': 1586191421319, 'price': '139449.00', 'volume': '0.001918', 'is_buy': False}"
"{'sequence': 7933153, 'timestamp': 1586191420238, 'price': '139449.00', 'volume': '0.007831', 'is_buy': False}"
"{'sequence': 7933152, 'timestamp': 1586191420180, 'price': '139450.00', 'volume': '0.000954', 'is_buy': True}"
因此,我的输出现在是正确的:
看起来
xbtzartrades
有您需要的数据。您似乎不需要经历转换为JSON然后将文件读入pandas的所有中间步骤相关问题 更多 >
编程相关推荐