国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

基于pandas數(shù)據(jù)樣本行列選取的方法

2020-02-22 23:45:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

注:以下代碼是基于python3.5.0編寫的

import pandasfood_info = pandas.read_csv("food_info.csv")# ------------------選取數(shù)據(jù)樣本的第一行--------------------print(food_info.loc[0])#------------------選取數(shù)據(jù)樣本的3到6行----------------------print(food_info.loc[3:6])#------------------head選取數(shù)據(jù)樣本的前幾行------------------print(food_info.head(2))# ------------------選取數(shù)據(jù)樣本的2,5,10行,兩種方法-----------# print(food_info.loc[[2,5,10]])     #方法一 two_five_ten = [2,5,10]         #方法二print(food_info.loc[two_five_ten])# ------------------選取數(shù)據(jù)樣本的NDB_No列--------------------# ndb_col = food_info["NDB_No"]     #方法一 col_name = "NDB_No"           #方法二ndb_col = food_info[col_name]print(ndb_col)# ------------------選取數(shù)據(jù)樣本的多列-------------------# zinc_copper = food_info[["Zinc_(mg)", "Copper_(mg)"]]columns = ["Zinc_(mg)", "Copper_(mg)"]zinc_copper = food_info[columns]print(zinc_copper)# ---------------------綜合小例子----------------------------col_names = food_info.columns.tolist()   #把所有的行轉(zhuǎn)化成listprint(col_names)gram_columns = []for c in col_names:            #遍歷col_names,找出所有以(g)結(jié)尾的位置  if c.endswith("(g)"):    gram_columns.append(c)print(gram_columns)gram_df = food_info[gram_columns]     #把所有以(g)結(jié)尾的列存放到gram_dfprint(gram_df.head(3)) 

以上這篇基于pandas數(shù)據(jù)樣本行列選取的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長(zhǎng)站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 织金县| 新宁县| 锡林郭勒盟| 华亭县| 大城县| 台前县| 九寨沟县| 乌恰县| 体育| 通州区| 泽库县| 邛崃市| 乐业县| 广水市| 新沂市| 元朗区| 沈丘县| 宁乡县| 玛纳斯县| 天峨县| 酒泉市| 丰台区| 淮阳县| 大关县| 吉木萨尔县| 鄢陵县| 溧水县| 松阳县| 东山县| 顺昌县| 枞阳县| 延吉市| 盱眙县| 通河县| 泾阳县| 建德市| 石城县| 合川市| 凉城县| 邵武市| 天台县|