我在 Panda Dataframe 下面有三個記錄。

我一次只能使用一行來進行 JSON 展平,但我嘗試了它不起作用的所有行。單行的 JSON 展平。

對于所有行,我都需要幫助,因為下面的代碼對我根本不起作用

我的資料框:
df = pd.DataFrame(
columns=['data'],
data=[
[{ "answers_interface": { "__id": 1, "flags": {}, "heloc": 3 ,"balloon": 4 }}],
[{ "answers_interface": { "__id": 2, "flags": {}, "heloc": 3, "balloon": 4 }}]
])
uj5u.com熱心網友回復:
轉換df['data']為串列,然后使用json_normalize:
out = pd.json_normalize(df['data'].tolist())
輸出:
answers_interface.__id answers_interface.heloc answers_interface.balloon
0 1 3 4
1 2 3 4
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/418595.html
標籤:
