日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python数据分析第七章实训3_《利用python进行数据分析》读书笔记--第七章 数据规整化:清理、转换、合并、重塑(三)...

發布時間:2023/12/20 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python数据分析第七章实训3_《利用python进行数据分析》读书笔记--第七章 数据规整化:清理、转换、合并、重塑(三)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#-*- encoding: utf-8 -*-

importnumpy as npimportpandas as pdimportmatplotlib.pyplot as pltfrom pandas importSeries,DataFrameimportreimportjson#加載下面30M+的數據

db = json.load(open('E:\\foods-2011-10-03.json'))#print len(db)#print type(db) #得到的db是個list,每個條目都是含有某種食物全部數據的字典#print db[0] #這一條非常長#print db[0].keys()#nutrients 是keys中的一個key,它對應的值是有關食物營養成分的一個字典列表,很長……#print db[0]['nutrients'][0]#下面將營養成分做成DataFrame

nutrients = DataFrame(db[0]['nutrients']) #將字典列表直接做成DataFrame#print nutrients.head()#print type(db[0]['nutrients'])

info_keys = ['description','group','id','manufacturer']

info= DataFrame(db,columns =info_keys)#print info#查看分類分布情況#print pd.value_counts(info.group)#現在,為了將所有的營養數據進行分析,需要將所有營養成分整合到一個大表中,下面分幾個步驟來完成

nutrients =[]for rec indb:

fnuts= DataFrame(rec['nutrients'])

fnuts['id'] = rec['id'] #廣播

nutrients.append(fnuts)

nutrients= pd.concat(nutrients,ignore_index = True) #將列表連接起來,相當于rbind,把行對其連接在一起

#去重,這是數據處理的重要步驟

printnutrients.duplicated().sum()

nutrients=nutrients.drop_duplicates()#由于nutrients與info有重復的名字,所以需要重命名一下info#注意下面這樣的命名方式

col_mapping = {'description':'food','group':'fgroup'}#rename函數返回的是副本,需要copy = False

info = info.rename(columns = col_mapping,copy =False)#print info.columns #查看一下列名

col_mapping = {'description':'nutrient','group':'nutgroup'}

nutrients= nutrients.rename(columns = col_mapping,copy =False)#print nutrients.columns#做完上面這些,顯然我們需要將兩個DataFrame合并起來

print nutrients.ix[:10,:]#print info.id

ndata = pd.merge(nutrients,info,on = 'id',how = 'outer')printndataprint ndata.ix[3000]#注意下面的處理方式很nice

result = ndata.groupby(['nutrient','fgroup'])['value'].quantile(0.5)printresult

result['Zinc, Zn'].order().plot(kind = 'barh')

plt.show()#只要稍微動動腦子(作者不止一次說過了……額),就可以發現各營養成分最為豐富的食物是什么了

by_nuttriend = ndata.groupby(['nutgroup','nutrient'])printby_nuttriend.head()#注意下面取出最大值的方式

get_maximum = lambdax:x.xs(x.value.idxmax())

get_minimum= lambdax:x.xs(x.value.idxmin())

max_foods= by_nuttriend.apply(get_maximum)[['value','food']]#讓food小一點

max_foods.food = max_foods.food.str[:50]printmax_foods.head()print max_foods.ix['Amino Acids']['food']

>>>

14179

nutrient nutgroup units value id

0 Protein Composition g 25.18 1008

1 Total lipid (fat) Composition g 29.20 1008

2 Carbohydrate, by difference Composition g 3.06 1008

3 Ash Other g 3.28 1008

4 Energy Energy kcal 376.00 1008

5 Water Composition g 39.28 1008

6 Energy Energy kJ 1573.00 1008

7 Fiber, total dietary Composition g 0.00 1008

8 Calcium, Ca Elements mg 673.00 1008

9 Iron, Fe Elements mg 0.64 1008

10 Magnesium, Mg Elements mg 22.00 1008

Int64Index: 375176 entries, 0 to 375175

Data columns:

nutrient 375176 non-null values

nutgroup 375176 non-null values

units 375176 non-null values

value 375176 non-null values

id 375176 non-null values

food 375176 non-null values

fgroup 375176 non-null values

manufacturer 293054 non-null values

dtypes: float64(1), int64(1), object(6)

nutrient Glycine

nutgroup Amino Acids

units g

value 0.073

id 1077

food Spearmint, fresh

fgroup Spices and Herbs

manufacturer

Name: 3000

nutrient fgroup

Adjusted Protein Sweets 12.900

Vegetables and Vegetable Products 2.180

Alanine Baby Foods 0.085

Baked Products 0.248

Beef Products 1.550

Beverages 0.003

Breakfast Cereals 0.311

Cereal Grains and Pasta 0.373

Dairy and Egg Products 0.271

Ethnic Foods 1.290

Fast Foods 0.514

Fats and Oils 0.000

Finfish and Shellfish Products 1.218

Fruits and Fruit Juices 0.027

Lamb, Veal, and Game Products 1.408

...

Zinc, Zn Finfish and Shellfish Products 0.67

Fruits and Fruit Juices 0.10

Lamb, Veal, and Game Products 3.94

Legumes and Legume Products 1.14

Meals, Entrees, and Sidedishes 0.63

Nut and Seed Products 3.29

Pork Products 2.32

Poultry Products 2.50

Restaurant Foods 0.80

Sausages and Luncheon Meats 2.13

Snacks 1.47

Soups, Sauces, and Gravies 0.20

Spices and Herbs 2.75

Sweets 0.36

Vegetables and Vegetable Products 0.33

Length: 2246

MultiIndex: 467 entries, (u'Amino Acids', u'Alanine', 48) to (u'Vitamins', u'Vitamin K (phylloquinone)', 395)

Data columns:

nutrient 467 non-null values

nutgroup 467 non-null values

units 467 non-null values

value 467 non-null values

id 467 non-null values

food 467 non-null values

fgroup 467 non-null values

manufacturer 444 non-null values

dtypes: float64(1), int64(1), object(6)

value food

nutgroup nutrient

Amino Acids Alanine 8.009 Gelatins, dry powder, unsweetened

Arginine 7.436 Seeds, sesame flour, low-fat

Aspartic acid 10.203 Soy protein isolate

Cystine 1.307 Seeds, cottonseed flour, low fat (glandless)

Glutamic acid 17.452 Soy protein isolate

nutrient

Alanine Gelatins, dry powder, unsweetened

Arginine Seeds, sesame flour, low-fat

Aspartic acid Soy protein isolate

Cystine Seeds, cottonseed flour, low fat (glandless)

Glutamic acid Soy protein isolate

Glycine Gelatins, dry powder, unsweetened

Histidine Whale, beluga, meat, dried (Alaska Native)

Hydroxyproline KENTUCKY FRIED CHICKEN, Fried Chicken, ORIGINA...

Isoleucine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Leucine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Lysine Seal, bearded (Oogruk), meat, dried (Alaska Na...

Methionine Fish, cod, Atlantic, dried and salted

Phenylalanine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Proline Gelatins, dry powder, unsweetened

Serine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Threonine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Tryptophan Sea lion, Steller, meat with fat (Alaska Native)

Tyrosine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Valine Soy protein isolate, PROTEIN TECHNOLOGIES INTE...

Name: food

[Finished in 14.1s]

總結

以上是生活随笔為你收集整理的python数据分析第七章实训3_《利用python进行数据分析》读书笔记--第七章 数据规整化:清理、转换、合并、重塑(三)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产99久久久久久免费看 | 亚洲人妻电影一区 | 少妇做爰免费视频播放 | 欧美国产精品一区二区 | 欧美激情视频二区 | 欧美另类videosbestsex日本 | 久久视频一区二区三区 | 麻豆精品av | 毛片免费播放 | 国模无码大尺度一区二区三区 | 免费看大片a | 天天天干 | 久久久精品人妻一区二区三区四 | 国产性―交―乱―色―情人 | 五月天最新网址 | 自拍偷拍第5页 | 一级片大片 | 欧美中日韩在线 | xxxx色 | 成人在线网 | 干干干日日日 | 国产一区二区小说 | 久久亚洲综合色图 | 尤物av无码色av无码 | 综合色88| 天堂av资源在线观看 | 这里精品 | 东京热毛片 | 亚洲国产欧美一区二区三区深喉 | 一本到久久 | 久久神马影院 | 婷婷色中文 | 91精品视频免费在线观看 | 国产淫语对白 | 非洲一级黄色片 | 天天超碰| av最新地址 | 日本αv | 欧美日韩国产专区 | 人妻精油按摩bd高清中文字幕 | 国产夫妻自拍av | 亚洲永久 | 中文字幕无线精品亚洲乱码一区 | 米奇影视第四色 | 精品一区二区三区入口 | 一本加勒比北条麻妃 | 欧美毛片基地 | 6090伦理| 亚洲国产精品午夜久久久 | 日韩欧美不卡 | 欧美精品久久久久久久多人混战 | 极品尤物魔鬼身材啪啪仙踪林 | 欧美久久久久久又粗又大 | 老司机午夜福利视频 | 超碰成人97| 不卡一区二区在线 | 一级做a爱视频 | av动漫免费观看 | 国产精品-区区久久久狼 | 国产经典毛片 | 91精品999| avxx| 九九亚洲视频 | 免费黄色一区二区 | 久精品在线观看 | 最近最好的2019中文 | 天堂在线中文字幕 | 日本一区二区三区视频在线 | 人妻无码一区二区三区四区 | 欧美无极品 | 亚洲综合网址 | 日韩精品免费在线视频 | 国产精品日韩在线 | 亚洲综合国产精品 | 成人av一区二区在线观看 | 欧美破处女 | 天天干,天天操,天天射 | 国产夫妻露脸 | 快乐激情网 | 亚洲一区二区三区免费观看 | 国产人妻互换一区二区 | 亚洲深爱 | 日韩视频免费观看高清 | 这里只有精品国产 | 告诉我真相俄剧在线观看 | 国产一级二级在线 | 久久综合一区二区 | 国产精品久久久久久中文字 | 日韩电影在线一区二区 | 性色欲情网站iwww九文堂 | 日日噜噜噜夜夜爽爽狠狠 | 日韩在线中文字幕 | 国产香蕉精品视频 | 免费草逼网站 | 日本护士╳╳╳hd少妇 | 色诱视频在线观看 | 特级西西444www大精品视频 | 日韩一区二区三区在线 | 精品国产青草久久久久96 |