# -*- coding: utf-8 -*-
import json
import pandas as pd
from pandas import DataFrame
db = json.load(open('usda_food/database.json'))
#print len(db)
#print db[0].keys()
#print db[0]['nutrients'][0]
nutrients = DataFrame(db[0]['nutrients'])
#print nutrients[:7]
#取出食物名称、分类、编号以及制造商等信息
info_keys = ['description', 'group', 'id', 'manufacturer']
info = DataFrame(db, columns = info_keys)
#print info.head()
#查看食物分布情况
#print pd.value_counts(info.group)
#全部营养作分析
#营养成分制成表格
nutrients = []
for rec in db:
funts = DataFrame(rec['nutrients'])
funts['id'] = rec['id']
nutrients.append(funts)
nutrients = pd.concat(nutrients, ignore_index = True)
#print nutrients
#查看并丢弃重复值
#print nutrients.duplicated().sum()
nutrients = nutrients.drop_duplicates()
#print nutrients
#重命名
col_mapping = {'description' : 'food
数据分析:USDA食品数据库
最新推荐文章于 2020-09-21 20:10:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)