最初我使用openpyxl和.split()方法来分隔数据数组。这仍然留下了一些格式,但最重要的是我真的希望能够用熊猫做到这一点。
任何帮助都会很棒,谢谢!
编辑:此外,如果有人知道一些好的教程,大熊猫初学者将是伟大的!EDIT2:
Ami Tavory的回答引发了这个错误:
Traceback (most recent call last):
File "C:\Users\David\Desktop\Python\Coursera\Computational Finance\CAPM\Scatter\JSONparser.py", line 7, in <module>
data = json.load(open('ETH_USD.txt'))
File "C:\Python27\lib\json\__init__.py", line 290, in load
**kw)
File "C:\Python27\lib\json\__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 369, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 13409 - line 1 column 13426 (char 13408 - 13425)
EDIT3:这是我的代码:
# Import the JSON parser
import json
# and pandas
import pandas as pd
# Assuming the data is in stuff.txt
data = json.load(open('ETH_USD.txt'))
#bpd.DataFrame(data)
[Finished in 1.1s]
EDIT3:这就像一种享受:
# Import the JSON parser
import json
# and pandas
import pandas as pd
URL = 'http://cryptocoincharts.info/fast/period.php?pair=ETH-USDT&market=poloniex&time=alltime&resolution=1d'
data = pd.read_json(URL)
data = pd.DataFrame(data)
data.to_csv('ETH_USD_PANDAS.csv')
答案 0 :(得分:1)
有几种方法。根据您链接的文本格式,我认为这是最简单的:
# Import the JSON parser
import json
# and pandas
import pandas as pd
# Assuming the data is in stuff.txt
data = json.load(open('stuff.txt'))
pd.DataFrame(data)