使用 Python 的 ETL 和 ELT
Jake Roach
Data Engineer

大多数生成与使用的数据是非结构化数据

API(应用程序编程接口)
$$

JSON(JavaScript 对象表示法)
dict字典相似{
"key": "value",
...
"open": 0.121875
}
{
"timestamps": [863703000, 863789400, ...],
"open": [0.121875, 0.098438, ...],
"close": [...],
"volume": [...]
}
使用.read_json()函数
# 读取上述格式的 JSON 文件
raw_stock_data = pd.read_json("raw_stock_data.json", orient="columns")
数据并非总是可直接变为 DataFrame
{
"863703000": {
"volume": 1443120000,
"price": {
"close": 0.09791,
"open": 0.12187
}
},
"863789400": {
...
}, ...
}
import json
with open("raw_stock_data.json", "r") as file:
# 将文件加载为字典
raw_stock_data = json.load(file)
# 确认 raw_stock_data 变量的类型
print(type(raw_stock_data))
<class 'dict'>
使用 Python 的 ETL 和 ELT