当我使用 pandas 转换数据时,我正在努力显示来自 json 提要的所有小数。代码如下。
import pandas as pd
url = 'https://api.binance.com/api/v1/klines?interval=1m&symbol=VETBTC'
df = pd.read_json(url, orient='columns', precise_float=True)
df.columns = ["Open_time","Open","High","Low","Close","Volume","Close_time","Quote_AV","TradesNo","Taker_base","Taker_quote","Ignore"]
df['Open_time'] = pd.to_datetime(df['Open_time'],unit='ms')
df['Close_time'] = pd.to_datetime(df['Close_time'],unit='ms')
print df.head(10000)
输出是:
Open_time Open High Low Close Volume Close_time Quote_AV TradesNo Taker_base Taker_quote Ignore
0 2018-11-21 02:53:00 0.000001 0.000001 0.000001 0.000001 64166 2018-11-21 02:53:59.999 0.077268 6 44229 0.053344 0
1 2018-11-21 02:54:00 0.000001 0.000001 0.000001 0.000001 5030 2018-11-21 02:54:59.999 0.005996 2 1010 0.001212 0
2 2018-11-21 02:55:00 0.000001 0.000001 0.000001 0.000001 61463 2018-11-21 02:55:59.999 0.073756 2 61463 0.073756 0
3 2018-11-21 02:56:00 0.000001 0.000001 0.000001 0.000001 106492 2018-11-21 02:56:59.999 0.127790 2 106492 0.127790 0
4 2018-11-21 02:57:00 0.000001 0.000001 0.000001 0.000001 13215 2018-11-21 02:57:59.999 0.015858 1 13215 0.015858 0
5 2018-11-21 02:58:00 0.000001 0.000001 0.000001 0.000001 25991 2018-11-21 02:58:59.999 0.031181 2 25142 0.030170 0
6 2018-11-21 02:59:00 0.000001 0.000001 0.000001 0.000001 2024424 2018-11-21 02:59:59.999 2.429309 14 1157504 1.389005 0
7 2018-11-21 03:00:00 0.000001 0.000001 0.000001 0.000001 6500 2018-11-21 03:00:59.999 0.007865 1 6500 0.007865 0
8 2018-11-21 03:01:00 0.000001 0.000001 0.000001 0.000001 24128 2018-11-21 03:01:59.999 0.028954 2 0 0.000000 0
9 2018-11-21 03:02:00 0.000001 0.000001 0.000001 0.000001 1126289 2018-11-21 03:02:59.999 1.351547 2 0 0.000000 0
10 2018-11-21 03:03:00 0.000001 0.000001 0.000001 0.000001 91099 2018-11-21 03:03:59.999 0.109695 6 37571 0.045461 0
11 2018-11-21 03:04:00 0.000001 0.000001 0.000001 0.000001 71152 2018-11-21 03:04:59.999 0.086094 1 71152 0.086094 0
12 2018-11-21 03:05:00 0.000001 0.000001 0.000001 0.000001 12222 2018-11-21 03:05:59.999 0.014789 2 12222 0.014789 0
虽然 json 提要具有更多小数的值,例如:
0 1542768840000 1“ 0.00000119” 2“ 0.00000120” 3“ 0.00000119” 4“ 0.00000120” 5“ 5030.00000000” 6 154276889999999999 7“ 0.005999580
我尝试使用precision_float 选项,但它似乎没有做它应该做的事情。任何帮助将不胜感激。