我下面有Pandas DataFrame,需要用df.columns封装在Django模型名称和“ fields”字段名称中,将其转换为json格式。请参阅以下示例,了解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",
}
}
]
慕娘9325324
相关分类