【发布时间】:2018-12-10 00:38:46
【问题描述】:
我有下面的 Pandas DataFrame,需要将其转换为 json 格式,其中 df.columns 包含在 Django 模型名称和“fields”字段名称中。请参阅下面的示例,了解 json 的外观。我该怎么做?
df:
+-----------------+---------+------+
| Artist | Title | Year |
+-----------------+---------+------+
| Michael Jackson | Beat it | 1988 |
| Britney Spears | Lucky | 2012 |
| Justin Bieber | Baby | 2006 |
+-----------------+---------+------+
Json 文件输出:
[
{
"model": "profiles.track",
"fields": {
"artist": "Michael Jackson",
"title": "Beat it",
"year": "1988",
}
},
{
"model": "profiles.track",
"fields": {
"artist": "Britney Spears",
"title": "Lucky",
"year": "2012",
}
},
{
"model": "profiles.track",
"fields": {
"artist": "Justin Bieber",
"title": "Baby",
"year": "2006",
}
}
]
【问题讨论】:
-
模型总是
"profiles.track"? -
是的,模型总是“profiles.track”