Python 中的 ETL 与 ELT
Jake Roach
Data Engineer

大多数产出与消费的数据是非结构化数据

API (Application Programming Interface)
$$

JSON (JavaScript Object Notation)
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:
# Load the file into a dictionary
raw_stock_data = json.load(file)
# Confirm the type of the raw_stock_data variable
print(type(raw_stock_data))
<class 'dict'>
Python 中的 ETL 与 ELT