pandas用法小结

前言

  个人感觉网上对pandas的总结感觉不够详尽细致,在这里我对pandas做个相对细致的小结吧,在数据分析与人工智能方面会有所涉及到的东西在这里都说说吧,也是对自己学习的一种小结!

pandas用法的介绍

  安装部分我就不说了,装个pip,使用命令pip install pandas就可以安装了,在Ubuntu中可能会出现没有权限的提示,直接加上sudo即可,以下讲解都是建立在python3平台的讲解,python2类似,python3中安装的时候使用sudo pip3 install pandas即可。

pandas是Python的一个数据分析模块,是为了解决数据分析任务而创建的,纳入了大量的库和标准数据模型,提供了高效地操作大型数据集所需的工具。

pandas中的数据结构 :

  1. Series: 一维数组,类似于python中的基本数据结构list,区别是series只允许存储相同的数据类型,这样可以更有效的使用内存,提高运算效率。就像数据库中的列数据。
  2. DataFrame: 二维的表格型数据结构。很多功能与R中的data.frame类似。可以将DataFrame理解为Series的容器。
  3. Panel:三维的数组,可以理解为DataFrame的容器。

关于pandas的更多详细的介绍请参看:http://pandas.pydata.org/pandas-docs/stable/10min.html

感兴趣的同学还可以看看我之前写过的numpy用法小结,库中大部分用法和numpy类似,可以对比着看,方便理解

下面我们以一个food_info.csv数据集来为大家讲解pandas的基本用法,该数据文件有需要的同学可以加我好友私聊我,或者把你的请求发邮箱至i_love_sjtu@qq.com,感谢看此文的您的支持和理解~~~

1.read_csv

pandas.read_csv(""),这里我们讲解下,read_csv函数的意思是读取文件信息,用来处理数据信息,可以处理数据文件。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(type(food_info))
print(food_info.dtypes)

打印结果如下:

<class 'pandas.core.frame.DataFrame'>
NDB_No               int64
Shrt_Desc           object
Water_(g)          float64
Energ_Kcal           int64
Protein_(g)        float64
Lipid_Tot_(g)      float64
Ash_(g)            float64
Carbohydrt_(g)     float64
Fiber_TD_(g)       float64
Sugar_Tot_(g)      float64
Calcium_(mg)       float64
Iron_(mg)          float64
Magnesium_(mg)     float64
Phosphorus_(mg)    float64
Potassium_(mg)     float64
Sodium_(mg)        float64
Zinc_(mg)          float64
Copper_(mg)        float64
Manganese_(mg)     float64
Selenium_(mcg)     float64
Vit_C_(mg)         float64
Thiamin_(mg)       float64
Riboflavin_(mg)    float64
Niacin_(mg)        float64
Vit_B6_(mg)        float64
Vit_B12_(mcg)      float64
Vit_A_IU           float64
Vit_A_RAE          float64
Vit_E_(mg)         float64
Vit_D_mcg          float64
Vit_D_IU           float64
Vit_K_(mcg)        float64
FA_Sat_(g)         float64
FA_Mono_(g)        float64
FA_Poly_(g)        float64
Cholestrl_(mg)     float64
dtype: object

我解释一下上面的用法,genfromtxt传入了三个参数,第一个参数是数据文件,名为world_alcohol.txt,该数据文件有需要的同学可以加我好友私聊我,或者把你的请求发邮箱至i_love_sjtu@qq.com

然后delimiter是分隔符,由于数据集中的数据是用逗号分隔的,所以设定参数delimiter=',',dtype是获取数据类型,数据集中的类型为str

print(type(food_info))打印数据文件的数据类型

print(food_info.dtypes)打印每一列数据的格式

2.shape

xxx.shape 显示的功能是查看数据表的维度数

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.shape)

打印结果:

(8618, 36)

显示出当前表的维度是8618行36列。

3.info()

xxx.info()获取数据表基本信息(维度、列名称、数据格式、所占空间等)

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.info())

打印结果:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 8618 entries, 0 to 8617
Data columns (total 36 columns):
NDB_No             8618 non-null int64
Shrt_Desc          8618 non-null object
Water_(g)          8612 non-null float64
Energ_Kcal         8618 non-null int64
Protein_(g)        8618 non-null float64
Lipid_Tot_(g)      8618 non-null float64
Ash_(g)            8286 non-null float64
Carbohydrt_(g)     8618 non-null float64
Fiber_TD_(g)       7962 non-null float64
Sugar_Tot_(g)      6679 non-null float64
Calcium_(mg)       8264 non-null float64
Iron_(mg)          8471 non-null float64
Magnesium_(mg)     7936 non-null float64
Phosphorus_(mg)    8046 non-null float64
Potassium_(mg)     8208 non-null float64
Sodium_(mg)        8535 non-null float64
Zinc_(mg)          7917 non-null float64
Copper_(mg)        7363 non-null float64
Manganese_(mg)     6478 non-null float64
Selenium_(mcg)     6868 non-null float64
Vit_C_(mg)         7826 non-null float64
Thiamin_(mg)       7939 non-null float64
Riboflavin_(mg)    7961 non-null float64
Niacin_(mg)        7937 non-null float64
Vit_B6_(mg)        7677 non-null float64
Vit_B12_(mcg)      7427 non-null float64
Vit_A_IU           7932 non-null float64
Vit_A_RAE          7089 non-null float64
Vit_E_(mg)         5613 non-null float64
Vit_D_mcg          5319 non-null float64
Vit_D_IU           5320 non-null float64
Vit_K_(mcg)        4969 non-null float64
FA_Sat_(g)         8274 non-null float64
FA_Mono_(g)        7947 non-null float64
FA_Poly_(g)        7954 non-null float64
Cholestrl_(mg)     8250 non-null float64
dtypes: float64(33), int64(2), object(1)
memory usage: 2.4+ MB

4.dtypes和astypes

xxx.dtypes是显示每一列数据的格式,可以指定某一列。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.dtypes)

打印结果:

NDB_No               int64
Shrt_Desc           object
Water_(g)          float64
Energ_Kcal           int64
Protein_(g)        float64
Lipid_Tot_(g)      float64
Ash_(g)            float64
Carbohydrt_(g)     float64
Fiber_TD_(g)       float64
Sugar_Tot_(g)      float64
Calcium_(mg)       float64
Iron_(mg)          float64
Magnesium_(mg)     float64
Phosphorus_(mg)    float64
Potassium_(mg)     float64
Sodium_(mg)        float64
Zinc_(mg)          float64
Copper_(mg)        float64
Manganese_(mg)     float64
Selenium_(mcg)     float64
Vit_C_(mg)         float64
Thiamin_(mg)       float64
Riboflavin_(mg)    float64
Niacin_(mg)        float64
Vit_B6_(mg)        float64
Vit_B12_(mcg)      float64
Vit_A_IU           float64
Vit_A_RAE          float64
Vit_E_(mg)         float64
Vit_D_mcg          float64
Vit_D_IU           float64
Vit_K_(mcg)        float64
FA_Sat_(g)         float64
FA_Mono_(g)        float64
FA_Poly_(g)        float64
Cholestrl_(mg)     float64
dtype: object

而如果我们想转换表中指定列的数据类型 我们应该使用astype进行转换

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info['NDB_No'].astype('float64'))

打印结果:

0        1001.0
1        1002.0
2        1003.0
3        1004.0
4        1005.0
5        1006.0
6        1007.0
7        1008.0
8        1009.0
9        1010.0
10       1011.0
11       1012.0
12       1013.0
13       1014.0
14       1015.0
15       1016.0
16       1017.0
17       1018.0
18       1019.0
19       1020.0
20       1021.0
21       1022.0
22       1023.0
23       1024.0
24       1025.0
25       1026.0
26       1027.0
27       1028.0
28       1029.0
29       1030.0
         ...
8588    43544.0
8589    43546.0
8590    43550.0
8591    43566.0
8592    43570.0
8593    43572.0
8594    43585.0
8595    43589.0
8596    43595.0
8597    43597.0
8598    43598.0
8599    44005.0
8600    44018.0
8601    44048.0
8602    44055.0
8603    44061.0
8604    44074.0
8605    44110.0
8606    44158.0
8607    44203.0
8608    44258.0
8609    44259.0
8610    44260.0
8611    48052.0
8612    80200.0
8613    83110.0
8614    90240.0
8615    90480.0
8616    90560.0
8617    93600.0
Name: NDB_No, Length: 8618, dtype: float64

原来NDB_No是int64类型,现在转换为float64类型了

5.isnull()

xxx.isnull() 用来查看数据表或者某一列数据的值是否为空值。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.isnull())

打印结果:

      NDB_No  Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  Lipid_Tot_(g)  \
0      False      False      False       False        False          False
1      False      False      False       False        False          False
2      False      False      False       False        False          False
3      False      False      False       False        False          False
4      False      False      False       False        False          False
5      False      False      False       False        False          False
6      False      False      False       False        False          False
7      False      False      False       False        False          False
8      False      False      False       False        False          False
9      False      False      False       False        False          False
10     False      False      False       False        False          False
11     False      False      False       False        False          False
12     False      False      False       False        False          False
13     False      False      False       False        False          False
14     False      False      False       False        False          False
15     False      False      False       False        False          False
16     False      False      False       False        False          False
17     False      False      False       False        False          False
18     False      False      False       False        False          False
19     False      False      False       False        False          False
20     False      False      False       False        False          False
21     False      False      False       False        False          False
22     False      False      False       False        False          False
23     False      False      False       False        False          False
24     False      False      False       False        False          False
25     False      False      False       False        False          False
26     False      False      False       False        False          False
27     False      False      False       False        False          False
28     False      False      False       False        False          False
29     False      False      False       False        False          False
...      ...        ...        ...         ...          ...            ...
8588   False      False      False       False        False          False
8589   False      False      False       False        False          False
8590   False      False      False       False        False          False
8591   False      False      False       False        False          False
8592   False      False      False       False        False          False
8593   False      False      False       False        False          False
8594   False      False      False       False        False          False
8595   False      False      False       False        False          False
8596   False      False      False       False        False          False
8597   False      False      False       False        False          False
8598   False      False      False       False        False          False
8599   False      False      False       False        False          False
8600   False      False      False       False        False          False
8601   False      False      False       False        False          False
8602   False      False      False       False        False          False
8603   False      False      False       False        False          False
8604   False      False      False       False        False          False
8605   False      False      False       False        False          False
8606   False      False      False       False        False          False
8607   False      False      False       False        False          False
8608   False      False      False       False        False          False
8609   False      False      False       False        False          False
8610   False      False      False       False        False          False
8611   False      False      False       False        False          False
8612   False      False      False       False        False          False
8613   False      False      False       False        False          False
8614   False      False      False       False        False          False
8615   False      False      False       False        False          False
8616   False      False      False       False        False          False
8617   False      False      False       False        False          False

      Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)       ...        \
0       False           False         False          False       ...
1       False           False         False          False       ...
2       False           False         False          False       ...
3       False           False         False          False       ...
4       False           False         False          False       ...
5       False           False         False          False       ...
6       False           False         False          False       ...
7       False           False         False           True       ...
8       False           False         False          False       ...
9       False           False         False           True       ...
10      False           False         False          False       ...
11      False           False         False          False       ...
12      False           False         False          False       ...
13      False           False         False          False       ...
14      False           False         False          False       ...
15      False           False         False          False       ...
16      False           False         False          False       ...
17      False           False         False          False       ...
18      False           False         False          False       ...
19      False           False         False          False       ...
20      False           False         False           True       ...
21      False           False         False          False       ...
22      False           False         False          False       ...
23      False           False         False          False       ...
24      False           False         False          False       ...
25      False           False         False          False       ...
26      False           False         False          False       ...
27      False           False         False          False       ...
28      False           False         False          False       ...
29      False           False         False          False       ...
...       ...             ...           ...            ...       ...
8588    False           False         False          False       ...
8589    False           False         False          False       ...
8590    False           False         False          False       ...
8591    False           False         False          False       ...
8592    False           False         False          False       ...
8593    False           False         False          False       ...
8594    False           False         False          False       ...
8595    False           False         False          False       ...
8596    False           False         False          False       ...
8597    False           False         False          False       ...
8598    False           False         False          False       ...
8599    False           False         False          False       ...
8600    False           False         False          False       ...
8601    False           False         False          False       ...
8602    False           False         False          False       ...
8603    False           False         False          False       ...
8604    False           False         False           True       ...
8605    False           False         False          False       ...
8606    False           False         False          False       ...
8607    False           False         False          False       ...
8608    False           False         False          False       ...
8609    False           False         False          False       ...
8610    False           False         False          False       ...
8611    False           False         False          False       ...
8612    False           False         False          False       ...
8613    False           False         False          False       ...
8614    False           False         False          False       ...
8615    False           False         False          False       ...
8616    False           False         False          False       ...
8617    False           False         False          False       ...

      Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  Vit_K_(mcg)  \
0        False      False       False      False     False        False
1        False      False       False      False     False        False
2        False      False       False      False     False        False
3        False      False       False      False     False        False
4        False      False       False      False     False        False
5        False      False       False      False     False        False
6        False      False       False      False     False        False
7        False      False        True       True      True         True
8        False      False       False      False     False        False
9        False      False        True       True      True         True
10       False      False       False      False     False        False
11       False      False       False      False     False        False
12       False      False       False      False     False        False
13       False      False       False      False     False        False
14       False      False       False      False     False        False
15       False      False       False      False     False        False
16       False      False       False      False     False        False
17       False      False       False      False     False        False
18       False      False       False      False     False        False
19       False      False       False      False     False        False
20       False      False        True       True      True         True
21       False      False       False      False     False        False
22       False      False       False      False     False        False
23       False      False       False      False     False        False
24       False      False       False      False     False        False
25       False      False       False      False     False        False
26       False      False       False      False     False        False
27       False      False       False      False     False        False
28       False      False       False      False     False        False
29       False      False       False      False     False        False
...        ...        ...         ...        ...       ...          ...
8588     False      False       False      False     False        False
8589     False      False       False      False     False        False
8590     False      False       False      False     False        False
8591     False      False       False      False     False        False
8592     False      False       False      False     False        False
8593     False      False       False      False     False        False
8594     False      False       False      False     False        False
8595     False      False       False      False     False        False
8596     False      False       False      False     False        False
8597     False      False       False      False     False        False
8598     False      False       False      False     False        False
8599     False      False       False      False     False        False
8600     False      False       False      False     False        False
8601     False      False       False      False     False        False
8602     False      False       False      False     False        False
8603     False      False       False      False     False        False
8604     False       True        True       True      True         True
8605     False      False       False      False     False        False
8606     False      False       False      False     False        False
8607     False      False       False      False     False        False
8608     False      False       False      False     False        False
8609     False      False       False      False     False        False
8610     False      False       False      False     False        False
8611     False      False       False      False     False        False
8612     False      False       False      False     False        False
8613     False      False       False      False     False        False
8614     False      False       False      False     False        False
8615     False      False       False      False     False        False
8616     False      False       False      False     False        False
8617     False      False       False      False     False        False

      FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)
0          False        False        False           False
1          False        False        False           False
2          False        False        False           False
3          False        False        False           False
4          False        False        False           False
5          False        False        False           False
6          False        False        False           False
7          False        False        False           False
8          False        False        False           False
9          False        False        False           False
10         False        False        False           False
11         False        False        False           False
12         False        False        False           False
13         False        False        False           False
14         False        False        False           False
15         False        False        False           False
16         False        False        False           False
17         False        False        False           False
18         False        False        False           False
19         False        False        False           False
20         False        False        False           False
21         False        False        False           False
22         False        False        False           False
23         False        False        False           False
24         False        False        False           False
25         False        False        False           False
26         False        False        False           False
27         False        False        False           False
28         False        False        False           False
29         False        False        False           False
...          ...          ...          ...             ...
8588       False        False        False           False
8589       False        False        False           False
8590       False        False        False           False
8591       False        False        False           False
8592       False        False        False           False
8593       False        False        False           False
8594       False        False        False           False
8595       False        False        False           False
8596       False        False        False           False
8597       False        False        False           False
8598       False        False        False           False
8599       False        False        False           False
8600       False        False        False           False
8601       False        False        False           False
8602       False        False        False           False
8603       False        False        False           False
8604       False        False        False           False
8605       False        False        False           False
8606       False        False        False           False
8607       False        False        False           False
8608       False        False        False           False
8609       False        False        False           False
8610       False        False        False           False
8611       False        False        False           False
8612       False        False        False           False
8613       False        False        False           False
8614       False        False        False           False
8615       False        False        False           False
8616       False        False        False           False
8617       False        False        False           False

[8618 rows x 36 columns]

6.columns

xxx.columns可以用来查看数据表中列的名称

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.columns)

打印结果:

Index(['NDB_No', 'Shrt_Desc', 'Water_(g)', 'Energ_Kcal', 'Protein_(g)',
       'Lipid_Tot_(g)', 'Ash_(g)', 'Carbohydrt_(g)', 'Fiber_TD_(g)',
       'Sugar_Tot_(g)', 'Calcium_(mg)', 'Iron_(mg)', 'Magnesium_(mg)',
       'Phosphorus_(mg)', 'Potassium_(mg)', 'Sodium_(mg)', 'Zinc_(mg)',
       'Copper_(mg)', 'Manganese_(mg)', 'Selenium_(mcg)', 'Vit_C_(mg)',
       'Thiamin_(mg)', 'Riboflavin_(mg)', 'Niacin_(mg)', 'Vit_B6_(mg)',
       'Vit_B12_(mcg)', 'Vit_A_IU', 'Vit_A_RAE', 'Vit_E_(mg)', 'Vit_D_mcg',
       'Vit_D_IU', 'Vit_K_(mcg)', 'FA_Sat_(g)', 'FA_Mono_(g)', 'FA_Poly_(g)',
       'Cholestrl_(mg)'],
      dtype='object')

7.head()和tail()

xxx.head()默认是用来查看前10行数据

而xxx.tail()默认用来查看后10行数据

可以传入参数x,指定查看前x行的数据

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.head())
print(food_info.tail())

打印结果:

   NDB_No                 Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  \
0    1001          BUTTER WITH SALT      15.87         717         0.85
1    1002  BUTTER WHIPPED WITH SALT      15.87         717         0.85
2    1003      BUTTER OIL ANHYDROUS       0.24         876         0.28
3    1004               CHEESE BLUE      42.41         353        21.40
4    1005              CHEESE BRICK      41.11         371        23.24

   Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)  \
0          81.11     2.11            0.06           0.0           0.06
1          81.11     2.11            0.06           0.0           0.06
2          99.48     0.00            0.00           0.0           0.00
3          28.74     5.11            2.34           0.0           0.50
4          29.68     3.18            2.79           0.0           0.51

        ...        Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  \
0       ...          2499.0      684.0        2.32        1.5      60.0
1       ...          2499.0      684.0        2.32        1.5      60.0
2       ...          3069.0      840.0        2.80        1.8      73.0
3       ...           721.0      198.0        0.25        0.5      21.0
4       ...          1080.0      292.0        0.26        0.5      22.0

   Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)
0          7.0      51.368       21.021        3.043           215.0
1          7.0      50.489       23.426        3.012           219.0
2          8.6      61.924       28.732        3.694           256.0
3          2.4      18.669        7.778        0.800            75.0
4          2.5      18.764        8.598        0.784            94.0

[5 rows x 36 columns]
      NDB_No                   Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  \
8613   83110             MACKEREL SALTED      43.00         305        18.50
8614   90240  SCALLOP (BAY&SEA) CKD STMD      70.25         111        20.54
8615   90480                  SYRUP CANE      26.00         269         0.00
8616   90560                   SNAIL RAW      79.20          90        16.10
8617   93600            TURTLE GREEN RAW      78.50          89        19.80

      Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)  \
8613          25.10    13.40            0.00           0.0            0.0
8614           0.84     2.97            5.41           0.0            0.0
8615           0.00     0.86           73.14           0.0           73.2
8616           1.40     1.30            2.00           0.0            0.0
8617           0.50     1.20            0.00           0.0            0.0

           ...        Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  \
8613       ...           157.0       47.0        2.38       25.2    1006.0
8614       ...             5.0        2.0        0.00        0.0       2.0
8615       ...             0.0        0.0        0.00        0.0       0.0
8616       ...           100.0       30.0        5.00        0.0       0.0
8617       ...           100.0       30.0        0.50        0.0       0.0

      Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)
8613          7.8       7.148        8.320        6.210            95.0
8614          0.0       0.218        0.082        0.222            41.0
8615          0.0       0.000        0.000        0.000             0.0
8616          0.1       0.361        0.259        0.252            50.0
8617          0.1       0.127        0.088        0.170            50.0

[5 rows x 36 columns]

8.index和values

xxx.index查看表的索引值

而xxx.values查看表的值

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.index)
print(food_info.values)

打印结果:

RangeIndex(start=0, stop=8618, step=1)
[[1001 'BUTTER WITH SALT' 15.87 ... 21.021 3.043 215.0]
 [1002 'BUTTER WHIPPED WITH SALT' 15.87 ... 23.426 3.012 219.0]
 [1003 'BUTTER OIL ANHYDROUS' 0.24 ... 28.732 3.694 256.0]
 ...
 [90480 'SYRUP CANE' 26.0 ... 0.0 0.0 0.0]
 [90560 'SNAIL RAW' 79.2 ... 0.259 0.252 50.0]
 [93600 'TURTLE GREEN RAW' 78.5 ... 0.08800000000000001 0.17 50.0]]

9.describe()

xxx.describe()用来查看数据的快速统计结果。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.describe())

打印结果:

<bound method NDFrame.describe of       NDB_No                                          Shrt_Desc  Water_(g)  \
0       1001                                   BUTTER WITH SALT      15.87
1       1002                           BUTTER WHIPPED WITH SALT      15.87
2       1003                               BUTTER OIL ANHYDROUS       0.24
3       1004                                        CHEESE BLUE      42.41
4       1005                                       CHEESE BRICK      41.11
5       1006                                        CHEESE BRIE      48.42
6       1007                                   CHEESE CAMEMBERT      51.80
7       1008                                     CHEESE CARAWAY      39.28
8       1009                                     CHEESE CHEDDAR      37.10
9       1010                                    CHEESE CHESHIRE      37.65
10      1011                                       CHEESE COLBY      38.20
11      1012                CHEESE COTTAGE CRMD LRG OR SML CURD      79.79
12      1013                        CHEESE COTTAGE CRMD W/FRUIT      79.64
13      1014   CHEESE COTTAGE NONFAT UNCRMD DRY LRG OR SML CURD      81.01
14      1015                   CHEESE COTTAGE LOWFAT 2% MILKFAT      81.24
15      1016                   CHEESE COTTAGE LOWFAT 1% MILKFAT      82.48
16      1017                                       CHEESE CREAM      54.44
17      1018                                        CHEESE EDAM      41.56
18      1019                                        CHEESE FETA      55.22
19      1020                                     CHEESE FONTINA      37.92
20      1021                                     CHEESE GJETOST      13.44
21      1022                                       CHEESE GOUDA      41.46
22      1023                                     CHEESE GRUYERE      33.19
23      1024                                   CHEESE LIMBURGER      48.42
24      1025                                    CHEESE MONTEREY      41.01
25      1026                         CHEESE MOZZARELLA WHL MILK      50.01
26      1027                CHEESE MOZZARELLA WHL MILK LO MOIST      48.38
27      1028                   CHEESE MOZZARELLA PART SKIM MILK      53.78
28      1029               CHEESE MOZZARELLA LO MOIST PART-SKIM      45.54
29      1030                                    CHEESE MUENSTER      41.77
...      ...                                                ...        ...
8588   43544         BABYFOOD CRL RICE W/ PEARS & APPL DRY INST       2.00
8589   43546                     BABYFOOD BANANA NO TAPIOCA STR      76.70
8590   43550                     BABYFOOD BANANA APPL DSSRT STR      83.10
8591   43566       SNACKS TORTILLA CHIPS LT (BAKED W/ LESS OIL)       1.30
8592   43570  CEREALS RTE POST HONEY BUNCHES OF OATS HONEY RSTD       5.00
8593   43572                         POPCORN MICROWAVE LOFAT&NA       2.80
8594   43585                       BABYFOOD FRUIT SUPREME DSSRT      81.60
8595   43589                               CHEESE SWISS LOW FAT      59.60
8596   43595             BREAKFAST BAR CORN FLAKE CRUST W/FRUIT      14.50
8597   43597                            CHEESE MOZZARELLA LO NA      49.90
8598   43598                           MAYONNAISE DRSNG NO CHOL      21.70
8599   44005                          OIL CORN PEANUT AND OLIVE       0.00
8600   44018                   SWEETENERS TABLETOP FRUCTOSE LIQ      23.90
8601   44048                              CHEESE FOOD IMITATION      55.50
8602   44055                                CELERY FLAKES DRIED       9.00
8603   44061           PUDDINGS CHOC FLAVOR LO CAL INST DRY MIX       4.20
8604   44074                    BABYFOOD GRAPE JUC NO SUGAR CND      84.40
8605   44110                   JELLIES RED SUGAR HOME PRESERVED      53.00
8606   44158                         PIE FILLINGS BLUEBERRY CND      54.66
8607   44203               COCKTAIL MIX NON-ALCOHOLIC CONCD FRZ      28.24
8608   44258            PUDDINGS CHOC FLAVOR LO CAL REG DRY MIX       6.80
8609   44259  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL REG DRY MIX      10.40
8610   44260  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL INST DRY...       6.84
8611   48052                                 VITAL WHEAT GLUTEN       8.20
8612   80200                                      FROG LEGS RAW      81.90
8613   83110                                    MACKEREL SALTED      43.00
8614   90240                         SCALLOP (BAY&SEA) CKD STMD      70.25
8615   90480                                         SYRUP CANE      26.00
8616   90560                                          SNAIL RAW      79.20
8617   93600                                   TURTLE GREEN RAW      78.50

      Energ_Kcal  Protein_(g)  Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  \
0            717         0.85          81.11     2.11            0.06
1            717         0.85          81.11     2.11            0.06
2            876         0.28          99.48     0.00            0.00
3            353        21.40          28.74     5.11            2.34
4            371        23.24          29.68     3.18            2.79
5            334        20.75          27.68     2.70            0.45
6            300        19.80          24.26     3.68            0.46
7            376        25.18          29.20     3.28            3.06
8            406        24.04          33.82     3.71            1.33
9            387        23.37          30.60     3.60            4.78
10           394        23.76          32.11     3.36            2.57
11            98        11.12           4.30     1.41            3.38
12            97        10.69           3.85     1.20            4.61
13            72        10.34           0.29     1.71            6.66
14            81        10.45           2.27     1.27            4.76
15            72        12.39           1.02     1.39            2.72
16           342         5.93          34.24     1.32            4.07
17           357        24.99          27.80     4.22            1.43
18           264        14.21          21.28     5.20            4.09
19           389        25.60          31.14     3.79            1.55
20           466         9.65          29.51     4.75           42.65
21           356        24.94          27.44     3.94            2.22
22           413        29.81          32.34     4.30            0.36
23           327        20.05          27.25     3.79            0.49
24           373        24.48          30.28     3.55            0.68
25           300        22.17          22.35     3.28            2.19
26           318        21.60          24.64     2.91            2.47
27           254        24.26          15.92     3.27            2.77
28           301        24.58          19.72     3.80            6.36
29           368        23.41          30.04     3.66            1.12
...          ...          ...            ...      ...             ...
8588         389         6.60           0.90     2.00           88.60
8589          91         1.00           0.20     0.76           21.34
8590          68         0.30           0.20     0.29           16.30
8591         465         8.70          15.20     1.85           73.40
8592         401         7.12           5.46     1.22           81.19
8593         429        12.60           9.50     1.71           73.39
8594          73         0.50           0.20     0.52           17.18
8595         179        28.40           5.10     3.50            3.40
8596         377         4.40           7.50     0.80           72.90
8597         280        27.50          17.10     2.40            3.10
8598         688         0.00          77.80     0.40            0.30
8599         884         0.00         100.00     0.00            0.00
8600         279         0.00           0.00     0.00           76.10
8601         257         4.08          19.50     4.74           16.18
8602         319        11.30           2.10    13.90           63.70
8603         356         5.30           2.40     9.90           78.20
8604          62         0.00           0.00     0.22           15.38
8605         179         0.30           0.03     0.08           46.10
8606         181         0.41           0.20     0.35           44.38
8607         287         0.08           0.01     0.07           71.60
8608         365        10.08           3.00     5.70           74.42
8609         351         1.60           0.10     1.86           86.04
8610         350         0.81           0.90     6.80           84.66
8611         370        75.16           1.85     1.00           13.79
8612          73        16.40           0.30     1.40            0.00
8613         305        18.50          25.10    13.40            0.00
8614         111        20.54           0.84     2.97            5.41
8615         269         0.00           0.00     0.86           73.14
8616          90        16.10           1.40     1.30            2.00
8617          89        19.80           0.50     1.20            0.00

      Fiber_TD_(g)  Sugar_Tot_(g)       ...        Vit_A_IU  Vit_A_RAE  \
0              0.0           0.06       ...          2499.0      684.0
1              0.0           0.06       ...          2499.0      684.0
2              0.0           0.00       ...          3069.0      840.0
3              0.0           0.50       ...           721.0      198.0
4              0.0           0.51       ...          1080.0      292.0
5              0.0           0.45       ...           592.0      174.0
6              0.0           0.46       ...           820.0      241.0
7              0.0            NaN       ...          1054.0      271.0
8              0.0           0.28       ...           994.0      263.0
9              0.0            NaN       ...           985.0      233.0
10             0.0           0.52       ...           994.0      264.0
11             0.0           2.67       ...           140.0       37.0
12             0.2           2.38       ...           146.0       38.0
13             0.0           1.85       ...             8.0        2.0
14             0.0           4.00       ...           225.0       68.0
15             0.0           2.72       ...            41.0       11.0
16             0.0           3.21       ...          1343.0      366.0
17             0.0           1.43       ...           825.0      243.0
18             0.0           4.09       ...           422.0      125.0
19             0.0           1.55       ...           913.0      261.0
20             0.0            NaN       ...          1113.0      334.0
21             0.0           2.22       ...           563.0      165.0
22             0.0           0.36       ...           948.0      271.0
23             0.0           0.49       ...          1155.0      340.0
24             0.0           0.50       ...           769.0      198.0
25             0.0           1.03       ...           676.0      179.0
26             0.0           1.01       ...           745.0      197.0
27             0.0           1.13       ...           481.0      127.0
28             0.0           2.24       ...           846.0      254.0
29             0.0           1.12       ...          1012.0      298.0
...            ...            ...       ...             ...        ...
8588           2.6           1.35       ...             0.0        0.0
8589           1.6          11.36       ...             5.0        0.0
8590           1.0          14.66       ...            30.0        2.0
8591           5.7           0.53       ...            81.0        4.0
8592           4.2          19.79       ...          2731.0      806.0
8593          14.2           0.54       ...           147.0        7.0
8594           2.0          14.87       ...            50.0        3.0
8595           0.0           1.33       ...           152.0       40.0
8596           2.1          35.10       ...          2027.0      608.0
8597           0.0           1.23       ...           517.0      137.0
8598           0.0           0.30       ...             0.0        0.0
8599           0.0           0.00       ...             0.0        0.0
8600           0.1          76.00       ...             0.0        0.0
8601           0.0           8.21       ...           900.0       45.0
8602          27.8          35.90       ...          1962.0       98.0
8603           6.1           0.70       ...             0.0        0.0
8604           0.1            NaN       ...             8.0        NaN
8605           0.8          45.30       ...             3.0        0.0
8606           2.6          37.75       ...            22.0        1.0
8607           0.0          24.53       ...            12.0        1.0
8608          10.1           0.70       ...             0.0        0.0
8609           0.9           2.90       ...             0.0        0.0
8610           0.8           0.90       ...             0.0        0.0
8611           0.6           0.00       ...             0.0        0.0
8612           0.0           0.00       ...            50.0       15.0
8613           0.0           0.00       ...           157.0       47.0
8614           0.0           0.00       ...             5.0        2.0
8615           0.0          73.20       ...             0.0        0.0
8616           0.0           0.00       ...           100.0       30.0
8617           0.0           0.00       ...           100.0       30.0

      Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  \
0           2.32        1.5      60.0          7.0      51.368       21.021
1           2.32        1.5      60.0          7.0      50.489       23.426
2           2.80        1.8      73.0          8.6      61.924       28.732
3           0.25        0.5      21.0          2.4      18.669        7.778
4           0.26        0.5      22.0          2.5      18.764        8.598
5           0.24        0.5      20.0          2.3      17.410        8.013
6           0.21        0.4      18.0          2.0      15.259        7.023
7            NaN        NaN       NaN          NaN      18.584        8.275
8           0.78        0.6      24.0          2.9      19.368        8.428
9            NaN        NaN       NaN          NaN      19.475        8.671
10          0.28        0.6      24.0          2.7      20.218        9.280
11          0.08        0.1       3.0          0.0       1.718        0.778
12          0.04        0.0       0.0          0.4       2.311        1.036
13          0.01        0.0       0.0          0.0       0.169        0.079
14          0.08        0.0       0.0          0.0       1.235        0.516
15          0.01        0.0       0.0          0.1       0.645        0.291
16          0.29        0.6      25.0          2.9      19.292        8.620
17          0.24        0.5      20.0          2.3      17.572        8.125
18          0.18        0.4      16.0          1.8      14.946        4.623
19          0.27        0.6      23.0          2.6      19.196        8.687
20           NaN        NaN       NaN          NaN      19.160        7.879
21          0.24        0.5      20.0          2.3      17.614        7.747
22          0.28        0.6      24.0          2.7      18.913       10.043
23          0.23        0.5      20.0          2.3      16.746        8.606
24          0.26        0.6      22.0          2.5      19.066        8.751
25          0.19        0.4      16.0          2.3      13.152        6.573
26          0.21        0.5      18.0          2.5      15.561        7.027
27          0.14        0.3      12.0          1.6      10.114        4.510
28          0.43        0.4      15.0          1.3      11.473        5.104
29          0.26        0.6      22.0          2.5      19.113        8.711
...          ...        ...       ...          ...         ...          ...
8588        0.13        0.0       0.0          0.3       0.185        0.252
8589        0.25        0.0       0.0          0.5       0.072        0.028
8590        0.02        0.0       0.0          0.1       0.058        0.018
8591        3.53        0.0       0.0          0.7       2.837        6.341
8592        1.22        4.6     183.0          3.0       0.600        2.831
8593        5.01        0.0       0.0         15.7       1.415        4.085
8594        0.79        0.0       0.0          5.1       0.030        0.025
8595        0.07        0.1       4.0          0.5       3.304        1.351
8596        0.76        0.0       0.0         13.8       1.500        5.000
8597        0.15        0.3      13.0          1.8      10.867        4.844
8598       11.79        0.0       0.0         24.7      10.784       18.026
8599       14.78        0.0       0.0         21.0      14.367       48.033
8600        0.00        0.0       0.0          0.0       0.000        0.000
8601        2.15        0.0       0.0         36.7       7.996        3.108
8602        5.55        0.0       0.0        584.2       0.555        0.405
8603        0.02        0.0       0.0          0.4       0.984        1.154
8604         NaN        NaN       NaN          NaN       0.000        0.000
8605        0.00        0.0       0.0          0.2       0.009        0.001
8606        0.23        0.0       0.0          3.9       0.000        0.000
8607        0.02        0.0       0.0          0.0       0.003        0.001
8608        0.02        0.0       0.0          0.5       1.578        1.150
8609        0.05        0.0       0.0          1.1       0.018        0.032
8610        0.08        0.0       0.0          1.7       0.099        0.116
8611        0.00        0.0       0.0          0.0       0.272        0.156
8612        1.00        0.2       8.0          0.1       0.076        0.053
8613        2.38       25.2    1006.0          7.8       7.148        8.320
8614        0.00        0.0       2.0          0.0       0.218        0.082
8615        0.00        0.0       0.0          0.0       0.000        0.000
8616        5.00        0.0       0.0          0.1       0.361        0.259
8617        0.50        0.0       0.0          0.1       0.127        0.088

      FA_Poly_(g)  Cholestrl_(mg)
0           3.043           215.0
1           3.012           219.0
2           3.694           256.0
3           0.800            75.0
4           0.784            94.0
5           0.826           100.0
6           0.724            72.0
7           0.830            93.0
8           1.433           102.0
9           0.870           103.0
10          0.953            95.0
11          0.123            17.0
12          0.124            13.0
13          0.003             7.0
14          0.083            12.0
15          0.031             4.0
16          1.437           110.0
17          0.665            89.0
18          0.591            89.0
19          1.654           116.0
20          0.938            94.0
21          0.657           114.0
22          1.733           110.0
23          0.495            90.0
24          0.899            89.0
25          0.765            79.0
26          0.778            89.0
27          0.472            64.0
28          0.861            65.0
29          0.661            96.0
...           ...             ...
8588        0.231             0.0
8589        0.041             0.0
8590        0.047             0.0
8591        5.024             0.0
8592        1.307             0.0
8593        3.572             0.0
8594        0.068             0.0
8595        0.180            35.0
8596        0.900             0.0
8597        0.509            54.0
8598       45.539             0.0
8599       33.033             0.0
8600        0.000             0.0
8601        7.536             6.0
8602        1.035             0.0
8603        0.131             0.0
8604        0.000             0.0
8605        0.008             0.0
8606        0.000             0.0
8607        0.009             0.0
8608        0.130             0.0
8609        0.050             0.0
8610        0.433             0.0
8611        0.810             0.0
8612        0.102            50.0
8613        6.210            95.0
8614        0.222            41.0
8615        0.000             0.0
8616        0.252            50.0
8617        0.170            50.0

[8618 rows x 36 columns]>

10.T

xxx.T可以对数据进行行列转换。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.T)

打印结果:

                             0                         1     \
NDB_No                       1001                      1002
Shrt_Desc        BUTTER WITH SALT  BUTTER WHIPPED WITH SALT
Water_(g)                   15.87                     15.87
Energ_Kcal                    717                       717
Protein_(g)                  0.85                      0.85
Lipid_Tot_(g)               81.11                     81.11
Ash_(g)                      2.11                      2.11
Carbohydrt_(g)               0.06                      0.06
Fiber_TD_(g)                    0                         0
Sugar_Tot_(g)                0.06                      0.06
Calcium_(mg)                   24                        24
Iron_(mg)                    0.02                      0.16
Magnesium_(mg)                  2                         2
Phosphorus_(mg)                24                        23
Potassium_(mg)                 24                        26
Sodium_(mg)                   643                       659
Zinc_(mg)                    0.09                      0.05
Copper_(mg)                     0                     0.016
Manganese_(mg)                  0                     0.004
Selenium_(mcg)                  1                         1
Vit_C_(mg)                      0                         0
Thiamin_(mg)                0.005                     0.005
Riboflavin_(mg)             0.034                     0.034
Niacin_(mg)                 0.042                     0.042
Vit_B6_(mg)                 0.003                     0.003
Vit_B12_(mcg)                0.17                      0.13
Vit_A_IU                     2499                      2499
Vit_A_RAE                     684                       684
Vit_E_(mg)                   2.32                      2.32
Vit_D_mcg                     1.5                       1.5
Vit_D_IU                       60                        60
Vit_K_(mcg)                     7                         7
FA_Sat_(g)                 51.368                    50.489
FA_Mono_(g)                21.021                    23.426
FA_Poly_(g)                 3.043                     3.012
Cholestrl_(mg)                215                       219

                                 2            3             4            5     \
NDB_No                           1003         1004          1005         1006
Shrt_Desc        BUTTER OIL ANHYDROUS  CHEESE BLUE  CHEESE BRICK  CHEESE BRIE
Water_(g)                        0.24        42.41         41.11        48.42
Energ_Kcal                        876          353           371          334
Protein_(g)                      0.28         21.4         23.24        20.75
Lipid_Tot_(g)                   99.48        28.74         29.68        27.68
Ash_(g)                             0         5.11          3.18          2.7
Carbohydrt_(g)                      0         2.34          2.79         0.45
Fiber_TD_(g)                        0            0             0            0
Sugar_Tot_(g)                       0          0.5          0.51         0.45
Calcium_(mg)                        4          528           674          184
Iron_(mg)                           0         0.31          0.43          0.5
Magnesium_(mg)                      0           23            24           20
Phosphorus_(mg)                     3          387           451          188
Potassium_(mg)                      5          256           136          152
Sodium_(mg)                         2         1146           560          629
Zinc_(mg)                        0.01         2.66           2.6         2.38
Copper_(mg)                     0.001         0.04         0.024        0.019
Manganese_(mg)                      0        0.009         0.012        0.034
Selenium_(mcg)                      0         14.5          14.5         14.5
Vit_C_(mg)                          0            0             0            0
Thiamin_(mg)                    0.001        0.029         0.014         0.07
Riboflavin_(mg)                 0.005        0.382         0.351         0.52
Niacin_(mg)                     0.003        1.016         0.118         0.38
Vit_B6_(mg)                     0.001        0.166         0.065        0.235
Vit_B12_(mcg)                    0.01         1.22          1.26         1.65
Vit_A_IU                         3069          721          1080          592
Vit_A_RAE                         840          198           292          174
Vit_E_(mg)                        2.8         0.25          0.26         0.24
Vit_D_mcg                         1.8          0.5           0.5          0.5
Vit_D_IU                           73           21            22           20
Vit_K_(mcg)                       8.6          2.4           2.5          2.3
FA_Sat_(g)                     61.924       18.669        18.764        17.41
FA_Mono_(g)                    28.732        7.778         8.598        8.013
FA_Poly_(g)                     3.694          0.8         0.784        0.826
Cholestrl_(mg)                    256           75            94          100

                             6               7               8     \
NDB_No                       1007            1008            1009
Shrt_Desc        CHEESE CAMEMBERT  CHEESE CARAWAY  CHEESE CHEDDAR
Water_(g)                    51.8           39.28            37.1
Energ_Kcal                    300             376             406
Protein_(g)                  19.8           25.18           24.04
Lipid_Tot_(g)               24.26            29.2           33.82
Ash_(g)                      3.68            3.28            3.71
Carbohydrt_(g)               0.46            3.06            1.33
Fiber_TD_(g)                    0               0               0
Sugar_Tot_(g)                0.46             NaN            0.28
Calcium_(mg)                  388             673             675
Iron_(mg)                    0.33            0.64            0.16
Magnesium_(mg)                 20              22              27
Phosphorus_(mg)               347             490             473
Potassium_(mg)                187              93              76
Sodium_(mg)                   842             690             644
Zinc_(mg)                    2.38            2.94            3.43
Copper_(mg)                 0.021           0.024           0.056
Manganese_(mg)              0.038           0.021           0.033
Selenium_(mcg)               14.5            14.5            28.3
Vit_C_(mg)                      0               0               0
Thiamin_(mg)                0.028           0.031           0.027
Riboflavin_(mg)             0.488            0.45           0.434
Niacin_(mg)                  0.63            0.18           0.039
Vit_B6_(mg)                 0.227           0.074           0.049
Vit_B12_(mcg)                 1.3            0.27            0.88
Vit_A_IU                      820            1054             994
Vit_A_RAE                     241             271             263
Vit_E_(mg)                   0.21             NaN            0.78
Vit_D_mcg                     0.4             NaN             0.6
Vit_D_IU                       18             NaN              24
Vit_K_(mcg)                     2             NaN             2.9
FA_Sat_(g)                 15.259          18.584          19.368
FA_Mono_(g)                 7.023           8.275           8.428
FA_Poly_(g)                 0.724            0.83           1.433
Cholestrl_(mg)                 72              93             102

                            9           ...         \
NDB_No                      1010        ...
Shrt_Desc        CHEESE CHESHIRE        ...
Water_(g)                  37.65        ...
Energ_Kcal                   387        ...
Protein_(g)                23.37        ...
Lipid_Tot_(g)               30.6        ...
Ash_(g)                      3.6        ...
Carbohydrt_(g)              4.78        ...
Fiber_TD_(g)                   0        ...
Sugar_Tot_(g)                NaN        ...
Calcium_(mg)                 643        ...
Iron_(mg)                   0.21        ...
Magnesium_(mg)                21        ...
Phosphorus_(mg)              464        ...
Potassium_(mg)                95        ...
Sodium_(mg)                  700        ...
Zinc_(mg)                   2.79        ...
Copper_(mg)                0.042        ...
Manganese_(mg)             0.012        ...
Selenium_(mcg)              14.5        ...
Vit_C_(mg)                     0        ...
Thiamin_(mg)               0.046        ...
Riboflavin_(mg)            0.293        ...
Niacin_(mg)                 0.08        ...
Vit_B6_(mg)                0.074        ...
Vit_B12_(mcg)               0.83        ...
Vit_A_IU                     985        ...
Vit_A_RAE                    233        ...
Vit_E_(mg)                   NaN        ...
Vit_D_mcg                    NaN        ...
Vit_D_IU                     NaN        ...
Vit_K_(mcg)                  NaN        ...
FA_Sat_(g)                19.475        ...
FA_Mono_(g)                8.671        ...
FA_Poly_(g)                 0.87        ...
Cholestrl_(mg)               103        ...

                                                    8608  \
NDB_No                                             44258
Shrt_Desc        PUDDINGS CHOC FLAVOR LO CAL REG DRY MIX
Water_(g)                                            6.8
Energ_Kcal                                           365
Protein_(g)                                        10.08
Lipid_Tot_(g)                                          3
Ash_(g)                                              5.7
Carbohydrt_(g)                                     74.42
Fiber_TD_(g)                                        10.1
Sugar_Tot_(g)                                        0.7
Calcium_(mg)                                          50
Iron_(mg)                                           3.87
Magnesium_(mg)                                       110
Phosphorus_(mg)                                      174
Potassium_(mg)                                       570
Sodium_(mg)                                         3326
Zinc_(mg)                                           1.49
Copper_(mg)                                        0.854
Manganese_(mg)                                     0.887
Selenium_(mcg)                                       5.1
Vit_C_(mg)                                             0
Thiamin_(mg)                                       0.025
Riboflavin_(mg)                                    0.105
Niacin_(mg)                                        0.545
Vit_B6_(mg)                                        0.027
Vit_B12_(mcg)                                          0
Vit_A_IU                                               0
Vit_A_RAE                                              0
Vit_E_(mg)                                          0.02
Vit_D_mcg                                              0
Vit_D_IU                                               0
Vit_K_(mcg)                                          0.5
FA_Sat_(g)                                         1.578
FA_Mono_(g)                                         1.15
FA_Poly_(g)                                         0.13
Cholestrl_(mg)                                         0

                                                              8609  \
NDB_No                                                       44259
Shrt_Desc        PUDDINGS ALL FLAVORS XCPT CHOC LO CAL REG DRY MIX
Water_(g)                                                     10.4
Energ_Kcal                                                     351
Protein_(g)                                                    1.6
Lipid_Tot_(g)                                                  0.1
Ash_(g)                                                       1.86
Carbohydrt_(g)                                               86.04
Fiber_TD_(g)                                                   0.9
Sugar_Tot_(g)                                                  2.9
Calcium_(mg)                                                    49
Iron_(mg)                                                     0.05
Magnesium_(mg)                                                  17
Phosphorus_(mg)                                                 12
Potassium_(mg)                                                  18
Sodium_(mg)                                                   1765
Zinc_(mg)                                                     0.19
Copper_(mg)                                                   0.04
Manganese_(mg)                                                 NaN
Selenium_(mcg)                                                 0.9
Vit_C_(mg)                                                       0
Thiamin_(mg)                                                     0
Riboflavin_(mg)                                                  0
Niacin_(mg)                                                      0
Vit_B6_(mg)                                                      0
Vit_B12_(mcg)                                                    0
Vit_A_IU                                                         0
Vit_A_RAE                                                        0
Vit_E_(mg)                                                    0.05
Vit_D_mcg                                                        0
Vit_D_IU                                                         0
Vit_K_(mcg)                                                    1.1
FA_Sat_(g)                                                   0.018
FA_Mono_(g)                                                  0.032
FA_Poly_(g)                                                   0.05
Cholestrl_(mg)                                                   0

                                                              8610  \
NDB_No                                                       44260
Shrt_Desc        PUDDINGS ALL FLAVORS XCPT CHOC LO CAL INST DRY...
Water_(g)                                                     6.84
Energ_Kcal                                                     350
Protein_(g)                                                   0.81
Lipid_Tot_(g)                                                  0.9
Ash_(g)                                                        6.8
Carbohydrt_(g)                                               84.66
Fiber_TD_(g)                                                   0.8
Sugar_Tot_(g)                                                  0.9
Calcium_(mg)                                                   143
Iron_(mg)                                                     0.38
Magnesium_(mg)                                                   5
Phosphorus_(mg)                                               2368
Potassium_(mg)                                                  30
Sodium_(mg)                                                   3750
Zinc_(mg)                                                      0.1
Copper_(mg)                                                  0.038
Manganese_(mg)                                               0.041
Selenium_(mcg)                                                 0.8
Vit_C_(mg)                                                       0
Thiamin_(mg)                                                 0.005
Riboflavin_(mg)                                              0.021
Niacin_(mg)                                                  0.014
Vit_B6_(mg)                                                  0.005
Vit_B12_(mcg)                                                 0.05
Vit_A_IU                                                         0
Vit_A_RAE                                                        0
Vit_E_(mg)                                                    0.08
Vit_D_mcg                                                        0
Vit_D_IU                                                         0
Vit_K_(mcg)                                                    1.7
FA_Sat_(g)                                                   0.099
FA_Mono_(g)                                                  0.116
FA_Poly_(g)                                                  0.433
Cholestrl_(mg)                                                   0

                               8611           8612             8613  \
NDB_No                        48052          80200            83110
Shrt_Desc        VITAL WHEAT GLUTEN  FROG LEGS RAW  MACKEREL SALTED
Water_(g)                       8.2           81.9               43
Energ_Kcal                      370             73              305
Protein_(g)                   75.16           16.4             18.5
Lipid_Tot_(g)                  1.85            0.3             25.1
Ash_(g)                           1            1.4             13.4
Carbohydrt_(g)                13.79              0                0
Fiber_TD_(g)                    0.6              0                0
Sugar_Tot_(g)                     0              0                0
Calcium_(mg)                    142             18               66
Iron_(mg)                       5.2            1.5              1.4
Magnesium_(mg)                   25             20               60
Phosphorus_(mg)                 260            147              254
Potassium_(mg)                  100            285              520
Sodium_(mg)                      29             58             4450
Zinc_(mg)                      0.85              1              1.1
Copper_(mg)                   0.182           0.25              0.1
Manganese_(mg)                  NaN            NaN              NaN
Selenium_(mcg)                 39.7           14.1             73.4
Vit_C_(mg)                        0              0                0
Thiamin_(mg)                      0           0.14             0.02
Riboflavin_(mg)                   0           0.25             0.19
Niacin_(mg)                       0            1.2              3.3
Vit_B6_(mg)                       0           0.12             0.41
Vit_B12_(mcg)                     0            0.4               12
Vit_A_IU                          0             50              157
Vit_A_RAE                         0             15               47
Vit_E_(mg)                        0              1             2.38
Vit_D_mcg                         0            0.2             25.2
Vit_D_IU                          0              8             1006
Vit_K_(mcg)                       0            0.1              7.8
FA_Sat_(g)                    0.272          0.076            7.148
FA_Mono_(g)                   0.156          0.053             8.32
FA_Poly_(g)                    0.81          0.102             6.21
Cholestrl_(mg)                    0             50               95

                                       8614        8615       8616  \
NDB_No                                90240       90480      90560
Shrt_Desc        SCALLOP (BAY&SEA) CKD STMD  SYRUP CANE  SNAIL RAW
Water_(g)                             70.25          26       79.2
Energ_Kcal                              111         269         90
Protein_(g)                           20.54           0       16.1
Lipid_Tot_(g)                          0.84           0        1.4
Ash_(g)                                2.97        0.86        1.3
Carbohydrt_(g)                         5.41       73.14          2
Fiber_TD_(g)                              0           0          0
Sugar_Tot_(g)                             0        73.2          0
Calcium_(mg)                             10          13         10
Iron_(mg)                              0.58         3.6        3.5
Magnesium_(mg)                           37          10        250
Phosphorus_(mg)                         426           8        272
Potassium_(mg)                          314          63        382
Sodium_(mg)                             667          58         70
Zinc_(mg)                              1.55        0.19          1
Copper_(mg)                           0.033        0.02        0.4
Manganese_(mg)                        0.029         NaN        NaN
Selenium_(mcg)                         21.7         0.7       27.4
Vit_C_(mg)                                0           0          0
Thiamin_(mg)                          0.012        0.13       0.01
Riboflavin_(mg)                       0.024        0.06       0.12
Niacin_(mg)                           1.076         0.1        1.4
Vit_B6_(mg)                           0.112           0       0.13
Vit_B12_(mcg)                          2.15           0        0.5
Vit_A_IU                                  5           0        100
Vit_A_RAE                                 2           0         30
Vit_E_(mg)                                0           0          5
Vit_D_mcg                                 0           0          0
Vit_D_IU                                  2           0          0
Vit_K_(mcg)                               0           0        0.1
FA_Sat_(g)                            0.218           0      0.361
FA_Mono_(g)                           0.082           0      0.259
FA_Poly_(g)                           0.222           0      0.252
Cholestrl_(mg)                           41           0         50

                             8617
NDB_No                      93600
Shrt_Desc        TURTLE GREEN RAW
Water_(g)                    78.5
Energ_Kcal                     89
Protein_(g)                  19.8
Lipid_Tot_(g)                 0.5
Ash_(g)                       1.2
Carbohydrt_(g)                  0
Fiber_TD_(g)                    0
Sugar_Tot_(g)                   0
Calcium_(mg)                  118
Iron_(mg)                     1.4
Magnesium_(mg)                 20
Phosphorus_(mg)               180
Potassium_(mg)                230
Sodium_(mg)                    68
Zinc_(mg)                       1
Copper_(mg)                  0.25
Manganese_(mg)                NaN
Selenium_(mcg)               16.8
Vit_C_(mg)                      0
Thiamin_(mg)                 0.12
Riboflavin_(mg)              0.15
Niacin_(mg)                   1.1
Vit_B6_(mg)                  0.12
Vit_B12_(mcg)                   1
Vit_A_IU                      100
Vit_A_RAE                      30
Vit_E_(mg)                    0.5
Vit_D_mcg                       0
Vit_D_IU                        0
Vit_K_(mcg)                   0.1
FA_Sat_(g)                  0.127
FA_Mono_(g)                 0.088
FA_Poly_(g)                  0.17
Cholestrl_(mg)                 50

[36 rows x 8618 columns]

11.set_index

xxx.set_index 设置索引列。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.set_index('Energ_Kcal'))

打印结果:

            NDB_No                                          Shrt_Desc  \
Energ_Kcal
717           1001                                   BUTTER WITH SALT
717           1002                           BUTTER WHIPPED WITH SALT
876           1003                               BUTTER OIL ANHYDROUS
353           1004                                        CHEESE BLUE
371           1005                                       CHEESE BRICK
334           1006                                        CHEESE BRIE
300           1007                                   CHEESE CAMEMBERT
376           1008                                     CHEESE CARAWAY
406           1009                                     CHEESE CHEDDAR
387           1010                                    CHEESE CHESHIRE
394           1011                                       CHEESE COLBY
98            1012                CHEESE COTTAGE CRMD LRG OR SML CURD
97            1013                        CHEESE COTTAGE CRMD W/FRUIT
72            1014   CHEESE COTTAGE NONFAT UNCRMD DRY LRG OR SML CURD
81            1015                   CHEESE COTTAGE LOWFAT 2% MILKFAT
72            1016                   CHEESE COTTAGE LOWFAT 1% MILKFAT
342           1017                                       CHEESE CREAM
357           1018                                        CHEESE EDAM
264           1019                                        CHEESE FETA
389           1020                                     CHEESE FONTINA
466           1021                                     CHEESE GJETOST
356           1022                                       CHEESE GOUDA
413           1023                                     CHEESE GRUYERE
327           1024                                   CHEESE LIMBURGER
373           1025                                    CHEESE MONTEREY
300           1026                         CHEESE MOZZARELLA WHL MILK
318           1027                CHEESE MOZZARELLA WHL MILK LO MOIST
254           1028                   CHEESE MOZZARELLA PART SKIM MILK
301           1029               CHEESE MOZZARELLA LO MOIST PART-SKIM
368           1030                                    CHEESE MUENSTER
...            ...                                                ...
389          43544         BABYFOOD CRL RICE W/ PEARS & APPL DRY INST
91           43546                     BABYFOOD BANANA NO TAPIOCA STR
68           43550                     BABYFOOD BANANA APPL DSSRT STR
465          43566       SNACKS TORTILLA CHIPS LT (BAKED W/ LESS OIL)
401          43570  CEREALS RTE POST HONEY BUNCHES OF OATS HONEY RSTD
429          43572                         POPCORN MICROWAVE LOFAT&NA
73           43585                       BABYFOOD FRUIT SUPREME DSSRT
179          43589                               CHEESE SWISS LOW FAT
377          43595             BREAKFAST BAR CORN FLAKE CRUST W/FRUIT
280          43597                            CHEESE MOZZARELLA LO NA
688          43598                           MAYONNAISE DRSNG NO CHOL
884          44005                          OIL CORN PEANUT AND OLIVE
279          44018                   SWEETENERS TABLETOP FRUCTOSE LIQ
257          44048                              CHEESE FOOD IMITATION
319          44055                                CELERY FLAKES DRIED
356          44061           PUDDINGS CHOC FLAVOR LO CAL INST DRY MIX
62           44074                    BABYFOOD GRAPE JUC NO SUGAR CND
179          44110                   JELLIES RED SUGAR HOME PRESERVED
181          44158                         PIE FILLINGS BLUEBERRY CND
287          44203               COCKTAIL MIX NON-ALCOHOLIC CONCD FRZ
365          44258            PUDDINGS CHOC FLAVOR LO CAL REG DRY MIX
351          44259  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL REG DRY MIX
350          44260  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL INST DRY...
370          48052                                 VITAL WHEAT GLUTEN
73           80200                                      FROG LEGS RAW
305          83110                                    MACKEREL SALTED
111          90240                         SCALLOP (BAY&SEA) CKD STMD
269          90480                                         SYRUP CANE
90           90560                                          SNAIL RAW
89           93600                                   TURTLE GREEN RAW

            Water_(g)  Protein_(g)  Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  \
Energ_Kcal
717             15.87         0.85          81.11     2.11            0.06
717             15.87         0.85          81.11     2.11            0.06
876              0.24         0.28          99.48     0.00            0.00
353             42.41        21.40          28.74     5.11            2.34
371             41.11        23.24          29.68     3.18            2.79
334             48.42        20.75          27.68     2.70            0.45
300             51.80        19.80          24.26     3.68            0.46
376             39.28        25.18          29.20     3.28            3.06
406             37.10        24.04          33.82     3.71            1.33
387             37.65        23.37          30.60     3.60            4.78
394             38.20        23.76          32.11     3.36            2.57
98              79.79        11.12           4.30     1.41            3.38
97              79.64        10.69           3.85     1.20            4.61
72              81.01        10.34           0.29     1.71            6.66
81              81.24        10.45           2.27     1.27            4.76
72              82.48        12.39           1.02     1.39            2.72
342             54.44         5.93          34.24     1.32            4.07
357             41.56        24.99          27.80     4.22            1.43
264             55.22        14.21          21.28     5.20            4.09
389             37.92        25.60          31.14     3.79            1.55
466             13.44         9.65          29.51     4.75           42.65
356             41.46        24.94          27.44     3.94            2.22
413             33.19        29.81          32.34     4.30            0.36
327             48.42        20.05          27.25     3.79            0.49
373             41.01        24.48          30.28     3.55            0.68
300             50.01        22.17          22.35     3.28            2.19
318             48.38        21.60          24.64     2.91            2.47
254             53.78        24.26          15.92     3.27            2.77
301             45.54        24.58          19.72     3.80            6.36
368             41.77        23.41          30.04     3.66            1.12
...               ...          ...            ...      ...             ...
389              2.00         6.60           0.90     2.00           88.60
91              76.70         1.00           0.20     0.76           21.34
68              83.10         0.30           0.20     0.29           16.30
465              1.30         8.70          15.20     1.85           73.40
401              5.00         7.12           5.46     1.22           81.19
429              2.80        12.60           9.50     1.71           73.39
73              81.60         0.50           0.20     0.52           17.18
179             59.60        28.40           5.10     3.50            3.40
377             14.50         4.40           7.50     0.80           72.90
280             49.90        27.50          17.10     2.40            3.10
688             21.70         0.00          77.80     0.40            0.30
884              0.00         0.00         100.00     0.00            0.00
279             23.90         0.00           0.00     0.00           76.10
257             55.50         4.08          19.50     4.74           16.18
319              9.00        11.30           2.10    13.90           63.70
356              4.20         5.30           2.40     9.90           78.20
62              84.40         0.00           0.00     0.22           15.38
179             53.00         0.30           0.03     0.08           46.10
181             54.66         0.41           0.20     0.35           44.38
287             28.24         0.08           0.01     0.07           71.60
365              6.80        10.08           3.00     5.70           74.42
351             10.40         1.60           0.10     1.86           86.04
350              6.84         0.81           0.90     6.80           84.66
370              8.20        75.16           1.85     1.00           13.79
73              81.90        16.40           0.30     1.40            0.00
305             43.00        18.50          25.10    13.40            0.00
111             70.25        20.54           0.84     2.97            5.41
269             26.00         0.00           0.00     0.86           73.14
90              79.20        16.10           1.40     1.30            2.00
89              78.50        19.80           0.50     1.20            0.00

            Fiber_TD_(g)  Sugar_Tot_(g)  Calcium_(mg)       ...        \
Energ_Kcal                                                  ...
717                  0.0           0.06          24.0       ...
717                  0.0           0.06          24.0       ...
876                  0.0           0.00           4.0       ...
353                  0.0           0.50         528.0       ...
371                  0.0           0.51         674.0       ...
334                  0.0           0.45         184.0       ...
300                  0.0           0.46         388.0       ...
376                  0.0            NaN         673.0       ...
406                  0.0           0.28         675.0       ...
387                  0.0            NaN         643.0       ...
394                  0.0           0.52         685.0       ...
98                   0.0           2.67          83.0       ...
97                   0.2           2.38          53.0       ...
72                   0.0           1.85          86.0       ...
81                   0.0           4.00         111.0       ...
72                   0.0           2.72          61.0       ...
342                  0.0           3.21          98.0       ...
357                  0.0           1.43         731.0       ...
264                  0.0           4.09         493.0       ...
389                  0.0           1.55         550.0       ...
466                  0.0            NaN         400.0       ...
356                  0.0           2.22         700.0       ...
413                  0.0           0.36        1011.0       ...
327                  0.0           0.49         497.0       ...
373                  0.0           0.50         746.0       ...
300                  0.0           1.03         505.0       ...
318                  0.0           1.01         575.0       ...
254                  0.0           1.13         782.0       ...
301                  0.0           2.24         716.0       ...
368                  0.0           1.12         717.0       ...
...                  ...            ...           ...       ...
389                  2.6           1.35          38.0       ...
91                   1.6          11.36           4.0       ...
68                   1.0          14.66           3.0       ...
465                  5.7           0.53         159.0       ...
401                  4.2          19.79          23.0       ...
429                 14.2           0.54          11.0       ...
73                   2.0          14.87           6.0       ...
179                  0.0           1.33         961.0       ...
377                  2.1          35.10          41.0       ...
280                  0.0           1.23         731.0       ...
688                  0.0           0.30           7.0       ...
884                  0.0           0.00           0.0       ...
279                  0.1          76.00           1.0       ...
257                  0.0           8.21         649.0       ...
319                 27.8          35.90         587.0       ...
356                  6.1           0.70         126.0       ...
62                   0.1            NaN          12.0       ...
179                  0.8          45.30           5.0       ...
181                  2.6          37.75          27.0       ...
287                  0.0          24.53           2.0       ...
365                 10.1           0.70          50.0       ...
351                  0.9           2.90          49.0       ...
350                  0.8           0.90         143.0       ...
370                  0.6           0.00         142.0       ...
73                   0.0           0.00          18.0       ...
305                  0.0           0.00          66.0       ...
111                  0.0           0.00          10.0       ...
269                  0.0          73.20          13.0       ...
90                   0.0           0.00          10.0       ...
89                   0.0           0.00         118.0       ...

            Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  Vit_K_(mcg)  \
Energ_Kcal
717           2499.0      684.0        2.32        1.5      60.0          7.0
717           2499.0      684.0        2.32        1.5      60.0          7.0
876           3069.0      840.0        2.80        1.8      73.0          8.6
353            721.0      198.0        0.25        0.5      21.0          2.4
371           1080.0      292.0        0.26        0.5      22.0          2.5
334            592.0      174.0        0.24        0.5      20.0          2.3
300            820.0      241.0        0.21        0.4      18.0          2.0
376           1054.0      271.0         NaN        NaN       NaN          NaN
406            994.0      263.0        0.78        0.6      24.0          2.9
387            985.0      233.0         NaN        NaN       NaN          NaN
394            994.0      264.0        0.28        0.6      24.0          2.7
98             140.0       37.0        0.08        0.1       3.0          0.0
97             146.0       38.0        0.04        0.0       0.0          0.4
72               8.0        2.0        0.01        0.0       0.0          0.0
81             225.0       68.0        0.08        0.0       0.0          0.0
72              41.0       11.0        0.01        0.0       0.0          0.1
342           1343.0      366.0        0.29        0.6      25.0          2.9
357            825.0      243.0        0.24        0.5      20.0          2.3
264            422.0      125.0        0.18        0.4      16.0          1.8
389            913.0      261.0        0.27        0.6      23.0          2.6
466           1113.0      334.0         NaN        NaN       NaN          NaN
356            563.0      165.0        0.24        0.5      20.0          2.3
413            948.0      271.0        0.28        0.6      24.0          2.7
327           1155.0      340.0        0.23        0.5      20.0          2.3
373            769.0      198.0        0.26        0.6      22.0          2.5
300            676.0      179.0        0.19        0.4      16.0          2.3
318            745.0      197.0        0.21        0.5      18.0          2.5
254            481.0      127.0        0.14        0.3      12.0          1.6
301            846.0      254.0        0.43        0.4      15.0          1.3
368           1012.0      298.0        0.26        0.6      22.0          2.5
...              ...        ...         ...        ...       ...          ...
389              0.0        0.0        0.13        0.0       0.0          0.3
91               5.0        0.0        0.25        0.0       0.0          0.5
68              30.0        2.0        0.02        0.0       0.0          0.1
465             81.0        4.0        3.53        0.0       0.0          0.7
401           2731.0      806.0        1.22        4.6     183.0          3.0
429            147.0        7.0        5.01        0.0       0.0         15.7
73              50.0        3.0        0.79        0.0       0.0          5.1
179            152.0       40.0        0.07        0.1       4.0          0.5
377           2027.0      608.0        0.76        0.0       0.0         13.8
280            517.0      137.0        0.15        0.3      13.0          1.8
688              0.0        0.0       11.79        0.0       0.0         24.7
884              0.0        0.0       14.78        0.0       0.0         21.0
279              0.0        0.0        0.00        0.0       0.0          0.0
257            900.0       45.0        2.15        0.0       0.0         36.7
319           1962.0       98.0        5.55        0.0       0.0        584.2
356              0.0        0.0        0.02        0.0       0.0          0.4
62               8.0        NaN         NaN        NaN       NaN          NaN
179              3.0        0.0        0.00        0.0       0.0          0.2
181             22.0        1.0        0.23        0.0       0.0          3.9
287             12.0        1.0        0.02        0.0       0.0          0.0
365              0.0        0.0        0.02        0.0       0.0          0.5
351              0.0        0.0        0.05        0.0       0.0          1.1
350              0.0        0.0        0.08        0.0       0.0          1.7
370              0.0        0.0        0.00        0.0       0.0          0.0
73              50.0       15.0        1.00        0.2       8.0          0.1
305            157.0       47.0        2.38       25.2    1006.0          7.8
111              5.0        2.0        0.00        0.0       2.0          0.0
269              0.0        0.0        0.00        0.0       0.0          0.0
90             100.0       30.0        5.00        0.0       0.0          0.1
89             100.0       30.0        0.50        0.0       0.0          0.1

            FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)
Energ_Kcal
717             51.368       21.021        3.043           215.0
717             50.489       23.426        3.012           219.0
876             61.924       28.732        3.694           256.0
353             18.669        7.778        0.800            75.0
371             18.764        8.598        0.784            94.0
334             17.410        8.013        0.826           100.0
300             15.259        7.023        0.724            72.0
376             18.584        8.275        0.830            93.0
406             19.368        8.428        1.433           102.0
387             19.475        8.671        0.870           103.0
394             20.218        9.280        0.953            95.0
98               1.718        0.778        0.123            17.0
97               2.311        1.036        0.124            13.0
72               0.169        0.079        0.003             7.0
81               1.235        0.516        0.083            12.0
72               0.645        0.291        0.031             4.0
342             19.292        8.620        1.437           110.0
357             17.572        8.125        0.665            89.0
264             14.946        4.623        0.591            89.0
389             19.196        8.687        1.654           116.0
466             19.160        7.879        0.938            94.0
356             17.614        7.747        0.657           114.0
413             18.913       10.043        1.733           110.0
327             16.746        8.606        0.495            90.0
373             19.066        8.751        0.899            89.0
300             13.152        6.573        0.765            79.0
318             15.561        7.027        0.778            89.0
254             10.114        4.510        0.472            64.0
301             11.473        5.104        0.861            65.0
368             19.113        8.711        0.661            96.0
...                ...          ...          ...             ...
389              0.185        0.252        0.231             0.0
91               0.072        0.028        0.041             0.0
68               0.058        0.018        0.047             0.0
465              2.837        6.341        5.024             0.0
401              0.600        2.831        1.307             0.0
429              1.415        4.085        3.572             0.0
73               0.030        0.025        0.068             0.0
179              3.304        1.351        0.180            35.0
377              1.500        5.000        0.900             0.0
280             10.867        4.844        0.509            54.0
688             10.784       18.026       45.539             0.0
884             14.367       48.033       33.033             0.0
279              0.000        0.000        0.000             0.0
257              7.996        3.108        7.536             6.0
319              0.555        0.405        1.035             0.0
356              0.984        1.154        0.131             0.0
62               0.000        0.000        0.000             0.0
179              0.009        0.001        0.008             0.0
181              0.000        0.000        0.000             0.0
287              0.003        0.001        0.009             0.0
365              1.578        1.150        0.130             0.0
351              0.018        0.032        0.050             0.0
350              0.099        0.116        0.433             0.0
370              0.272        0.156        0.810             0.0
73               0.076        0.053        0.102            50.0
305              7.148        8.320        6.210            95.0
111              0.218        0.082        0.222            41.0
269              0.000        0.000        0.000             0.0
90               0.361        0.259        0.252            50.0
89               0.127        0.088        0.170            50.0

[8618 rows x 35 columns]

12.sort_values

xxx.sort_values 按照特定列的值排序。

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.sort_values(by='Vit_D_IU'))

打印结果:

      NDB_No                                          Shrt_Desc  Water_(g)  \
3689   12109  COCONUT MEAT DRIED (DESICCATED) SWTND FLAKED P...      15.46
4167   14026         BEVERAGES ENERGY DRK SUGAR-FREE W/ GUARANA      98.35
4169   14028                              WHISKEY SOUR MIX BTLD      78.20
4171   14030  BEVERAGES ENERGY DRK ORIGINAL GRAPE LOADED CHE...      88.45
4172   14031  BEVERAGES H2O BTLD YUMBERRY POMEGRANATE W/ ANT...      98.75
4173   14033                 BEVERAGES ABBOTT EAS WHEY PROT PDR       6.61
4174   14034             ALCOHOLIC BEV CREME DE MENTHE 72 PROOF      28.30
4175   14035                  BEVERAGES ABBOTT EAS SOY PROT PDR       2.83
4177   14037  ALCOHOLIC BEV DISTILLED ALL (GIN RUM VODKA WHI...      66.60
4178   14038  BEVERAGES OCEAN SPRAY CRAN-ENERGY CRANBERRY EN...      96.18
4180   14042                BEVERAGES FORT LO CAL FRUIT JUC BEV      97.21
4185   14049               ALCOHOLIC BEV DISTILLED GIN 90 PROOF      62.10
4186   14050               ALCOHOLIC BEV DISTILLED RUM 80 PROOF      66.60
4191   14057                       ALCOHOLIC BEV WINE DSSRT SWT      70.51
4164   14022               BEVERAGES MONSTER ENERGY DRK LO CARB      98.35
4192   14058                    BEVERAGES WHEY PROT PDR ISOLATE       0.86
4195   14061                    BEVERAGES ENERGY DRK SUGAR FREE      99.11
4197   14063                  BEVERAGES CHOC PDR NO SUGAR ADDED       7.40
4198   14064                    BEVERAGES ORANGE JUC LT NO PULP      94.19
4199   14065                BEVERAGES HI-C FLASHIN' FRUIT PUNCH      87.49
4200   14066                        BEVERAGES PROT PDR WHEY BSD       3.44
4201   14067                         BEVERAGES PROT PDR SOY BSD       4.13
4202   14068           BEVERAGES KELLOGG'S SPL K20 PROT H2O MIX       3.95
4206   14073                               BEVERAGES ZEVIA COLA      98.36
4207   14074                 BEVERAGES ZEVIA COLA CAFFEINE FREE      98.87
4208   14075  BEVERAGES H2O BTLD NATURALLY SPARKLING (CARBON...      99.95
4209   14076         BEVERAGES ICELANDIC GLACIAL NAT SPRING H2O     100.00
4213   14082  BEVERAGES GEROLSTEINER BRUNNEN GMBH H2O BTLD N...      99.95
4215   14084                       ALCOHOLIC BEV WINE TABLE ALL      86.58
4194   14060  BEVERAGES ENERGY DRK W/ CARB H2O & HI FRUCTOSE...      84.52
...      ...                                                ...        ...
8345   36408  RESTAURANT LATINO PUPUSAS CON FRIJOLES (PUPUSA...      52.16
8350   36413                  RESTAURANT LATINO BLACK BEAN SOUP      75.91
8351   36414                       RESTAURANT LATINO TRIPE SOUP      83.41
8352   36415  RESTAURANT LATINO AREPA (UNLEAVENED CORNMEAL B...      50.80
8353   36416     RESTAURANT LATINO BUNUELOS (FRIED YEAST BREAD)      15.30
8354   36417                    RESTAURANT MEXICAN SPANISH RICE      58.54
8355   36418                     RESTAURANT MEXICAN REFRIED BNS      67.57
8356   36601              RESTAURANT CHINESE EGG ROLLS ASSORTED      50.60
8359   36604  CRACKER BARREL CHICK TENDERLOIN PLATTER FRIED ...      42.61
8360   36605        CRACKER BARREL COUNTRY FRIED SHRIMP PLATTER      46.08
8361   36606         CRACKER BARREL FARM RAISED CATFISH PLATTER      52.32
8362   36607                         CRACKER BARREL STEAK FRIES      51.32
8363   36608               CRACKER BARREL GRILLED SIRLOIN STEAK      59.40
8364   36609  CRACKER BARREL MACARONI N' CHS PLATE FROM KID'...      64.80
8365   36610                                  DENNY'S FRENCH FR      46.05
8366   36611                        DENNY'S MOZZARELLA CHS STKS      37.63
8367   36612                        DENNY'S GOLDEN FRIED SHRIMP      41.05
8368   36613             DENNY'S MACARONI & CHS FROM KID'S MENU      67.38
8369   36614  DENNY'S CHICK NUGGETS STAR SHAPED FROM KID'S MENU      39.25
8370   36615                          DENNY'S TOP SIRLOIN STEAK      61.82
8374   36620                    RESTAURANT CHINESE SHRIMP & VEG      84.06
8376   36622                 RESTAURANT CHINESE SWT & SOUR PORK      50.84
8377   36623                 RESTAURANT CHINESE CHICK CHOW MEIN      81.01
8382   36630           RESTAURANT ITALIAN SPAGHETTI W/ MEAT SAU      73.16
8383   36631                 OLIVE GARDEN SPAGHETTI W/ MEAT SAU      72.75
8384   36632     CARRABBA'S ITALIAN GRILL SPAGHETTI W/ MEAT SAU      73.32
8445   42270                                 ORANGE JUICE DRINK      86.20
8454   42286                        BABYFOOD GRN BNS&TURKEY STR      87.50
8527   43297                          PORK ORIENTAL STYLE DEHYD      21.80
8604   44074                    BABYFOOD GRAPE JUC NO SUGAR CND      84.40

      Energ_Kcal  Protein_(g)  Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  \
3689         456         3.13          27.99     1.57           51.85
4167           4         0.00           0.00     0.62            1.03
4169          87         0.10           0.10     0.20           21.40
4171          44         0.00           0.00     0.28           11.25
4172           5         0.00           0.00     0.00            1.25
4173         385        66.67           5.13     3.65           17.95
4174         371         0.00           0.30     0.01           41.60
4175         405        47.62           3.57     2.03           43.94
4177         231         0.00           0.00     0.01            0.00
4178          15         0.00           0.00     0.11            3.75
4180           4         0.00           0.00     2.09            0.70
4185         263         0.00           0.00     0.00            0.00
4186         231         0.00           0.00     0.00            0.00
4191         160         0.20           0.00     0.30           13.69
4164           5         0.00           0.00     0.40            1.38
4192         359        58.14           1.16    10.77           29.07
4195           4         0.42           0.00     0.06            0.42
4197         373         9.09           9.09    10.70           63.64
4198          21         0.21           0.00     0.19            5.42
4199          45         0.00           0.00     0.01           12.50
4200         352        78.13           1.56    10.55            6.25
4201         388        55.56           5.56     5.87           28.89
4202         380        35.20           0.60     1.85           58.40
4206           0         0.00           0.00     0.00            1.13
4207           0         0.00           0.00     0.01            1.13
4208           0         0.00           0.00     0.05            0.00
4209           0         0.00           0.00     0.00            0.00
4213           0         0.00           0.00     0.05            0.00
4215          83         0.07           0.00     0.24            2.72
4194          62         0.42           0.00     0.06           15.00
...          ...          ...            ...      ...             ...
8345         229         5.59           9.01     1.74           31.49
8350         103         5.10           2.57     1.63           14.79
8351          74         8.61           2.58     1.33            4.07
8352         219         5.48           5.38     1.19           37.14
8353         462         8.02          26.24     1.87           48.57
8354         185         3.28           5.29     1.72           31.16
8355         156         6.91           6.77     1.96           16.79
8356         250         8.28          11.94     1.89           27.29
8359         294        18.67          15.41     3.08           20.24
8360         287        12.62          16.77     3.13           21.40
8361         266        22.94          17.05     2.38            5.31
8362         255         3.26          13.18     1.37           30.87
8363         203        31.52           8.52     1.64            0.00
8364         192         6.46          11.51     1.64           15.58
8365         282         3.41          14.13     1.20           35.20
8366         324        13.56          17.87     3.72           27.22
8367         319        13.88          20.01     4.14           20.93
8368         150         5.19           4.92     1.35           21.16
8369         377        16.27          28.57     2.33           13.59
8370         182        28.90           7.34     1.80            0.14
8374          78         5.90           4.05     1.47            4.52
8376         270         8.91          15.66     1.25           23.34
8377          85         6.76           2.80     1.13            8.29
8382         121         5.79           3.59     1.06           16.40
8383         121         5.80           3.28     0.98           17.19
8384         122         5.87           3.92     1.18           15.71
8445          54         0.20           0.00     0.19           13.41
8454          51         4.10           1.50     1.55            5.35
8527         615        11.80          62.40     2.60            1.40
8604          62         0.00           0.00     0.22           15.38

      Fiber_TD_(g)  Sugar_Tot_(g)       ...        Vit_A_IU  Vit_A_RAE  \
3689           9.9          36.75       ...             0.0        0.0
4167           0.0           0.00       ...             0.0        0.0
4169           0.0          21.40       ...             0.0        0.0
4171           0.0          11.25       ...             0.0        0.0
4172           0.0           0.00       ...             0.0        0.0
4173           0.0           5.13       ...            54.0       15.0
4174           0.0          41.60       ...             0.0        0.0
4175           0.0          40.48       ...             0.0        0.0
4177           0.0           0.00       ...             0.0        0.0
4178           0.0           3.75       ...             0.0        0.0
4180           0.0           0.63       ...           400.0       20.0
4185           0.0           0.00       ...             0.0        0.0
4186           0.0           0.00       ...             0.0        0.0
4191           0.0           7.78       ...             0.0        0.0
4164           0.0           1.38       ...             0.0        0.0
4192           0.0           1.16       ...          2909.0      872.0
4195           0.0           0.00       ...             0.0        0.0
4197           9.1          27.27       ...             0.0        0.0
4198           0.0           4.17       ...           208.0       10.0
4199           0.0          12.50       ...             0.0        0.0
4200           3.1           0.00       ...             0.0        0.0
4201           6.7          22.22       ...             0.0        0.0
4202          37.5           2.00       ...             8.0        2.0
4206           0.0           0.00       ...             0.0        0.0
4207           0.0           0.00       ...             0.0        0.0
4208           0.0           0.00       ...             0.0        0.0
4209           0.0           0.00       ...             0.0        0.0
4213           0.0           0.00       ...             0.0        0.0
4215           0.0           0.79       ...             0.0        0.0
4194           0.0          13.75       ...             0.0        0.0
...            ...            ...       ...             ...        ...
8345           5.8           1.30       ...             NaN        NaN
8350           4.9           0.89       ...             2.0        1.0
8351           NaN            NaN       ...             0.0        0.0
8352           2.6           0.87       ...           213.0       61.0
8353           1.5          12.24       ...             NaN        NaN
8354           1.2           1.30       ...           100.0        6.0
8355           8.0           0.78       ...            37.0       11.0
8356           2.6            NaN       ...             NaN        NaN
8359           1.0           0.19       ...            10.0        2.0
8360           0.3            NaN       ...             5.0        1.0
8361           1.6            NaN       ...             0.0        0.0
8362           3.5           0.86       ...             NaN        NaN
8363           NaN            NaN       ...            23.0        7.0
8364           0.7           2.83       ...           254.0       67.0
8365           3.5           0.85       ...             NaN        NaN
8366           1.6           2.83       ...           343.0       96.0
8367           1.5           0.75       ...             6.0        2.0
8368           1.2           4.20       ...            58.0       15.0
8369           0.8           0.00       ...            58.0       17.0
8370           NaN            NaN       ...             NaN        NaN
8374           1.4           2.16       ...          1320.0       66.0
8376           1.0          10.34       ...           553.0       29.0
8377           1.0           1.74       ...           362.0       19.0
8382           1.6           1.82       ...           232.0       12.0
8383           1.7           1.67       ...           191.0       10.0
8384           1.5           1.96       ...           272.0       14.0
8445           0.2           9.36       ...            44.0        2.0
8454           1.4           1.39       ...           629.0       31.0
8527           0.0           0.00       ...             0.0        0.0
8604           0.1            NaN       ...             8.0        NaN

      Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  \
3689        0.00        0.0       0.0          0.0      26.396        1.377
4167        0.00        0.0       0.0          0.0       0.000        0.000
4169        0.00        0.0       0.0          0.0       0.008        0.002
4171        0.00        0.0       0.0          0.0       0.000        0.000
4172        0.56        0.0       0.0          0.0       0.000        0.000
4173        0.38        0.0       0.0          0.5       2.564        0.281
4174        0.00        0.0       0.0          0.0       0.014        0.015
4175        0.12        0.0       0.0          2.7       0.000        0.644
4177        0.00        0.0       0.0          0.0       0.000        0.000
4178        0.00        0.0       0.0          0.1       0.000        0.000
4180        1.14        0.0       0.0          0.1       0.000        0.000
4185        0.00        0.0       0.0          0.0       0.000        0.000
4186        0.00        0.0       0.0          0.0       0.000        0.000
4191        0.00        0.0       0.0          0.0       0.000        0.000
4164        0.00        0.0       0.0          0.0       0.000        0.000
4192        7.85        0.0       0.0         46.5       0.581        0.149
4195        0.00        0.0       0.0          0.0       0.000        0.000
4197        0.00        0.0       0.0          0.0       4.545        2.119
4198        1.25        0.0       0.0          0.0       0.000        0.000
4199        0.00        0.0       0.0          0.0       0.000        0.000
4200        0.00        0.0       0.0          0.0       0.781        0.158
4201        0.00        0.0       0.0          0.0       1.111        1.057
4202        0.00        0.0       0.0          0.0       0.236        0.146
4206        0.00        0.0       0.0          0.0       0.000        0.000
4207        0.00        0.0       0.0          0.0       0.000        0.000
4208        0.00        0.0       0.0          0.0       0.000        0.000
4209        0.00        0.0       0.0          0.0       0.000        0.000
4213        0.00        0.0       0.0          0.0       0.000        0.000
4215        0.00        0.0       0.0          0.0       0.000        0.000
4194        0.00        0.0       0.0          0.0       0.000        0.000
...          ...        ...       ...          ...         ...          ...
8345        0.36        NaN       NaN          7.4       2.188        2.986
8350        0.07        NaN       NaN          6.0       0.535        1.035
8351        0.38        NaN       NaN          2.3       1.045        1.124
8352        0.29        NaN       NaN          3.5       2.902        1.514
8353        0.98        NaN       NaN         25.8       6.834        9.415
8354        0.60        NaN       NaN         13.0       1.005        1.511
8355        0.45        NaN       NaN         13.3       1.840        1.834
8356         NaN        NaN       NaN         58.9       2.116        3.036
8359        1.27        NaN       NaN         33.3       2.830        3.426
8360        1.88        NaN       NaN          NaN       3.064        3.787
8361         NaN        NaN       NaN         24.7       3.249        4.577
8362        1.34        NaN       NaN         32.1       2.369        3.156
8363        0.46        NaN       NaN          1.0       3.045        3.405
8364        0.75        NaN       NaN          9.9       4.197        2.824
8365        0.98        NaN       NaN         28.8       2.534        3.408
8366        0.74        NaN       NaN         25.4       6.643        4.287
8367        2.61        NaN       NaN         35.3       3.515        4.772
8368        0.53        NaN       NaN          3.0       1.384        2.046
8369        1.91        NaN       NaN         36.6       5.606        9.817
8370         NaN        NaN       NaN          1.0       2.595        2.840
8374        0.99        NaN       NaN         52.0       0.633        0.817
8376        0.89        NaN       NaN         27.9       2.680        3.527
8377        0.43        NaN       NaN         22.0       0.490        0.613
8382        0.63        NaN       NaN          4.2       1.062        1.486
8383        0.58        NaN       NaN          4.3       1.024        1.242
8384        0.68        NaN       NaN          3.3       1.100        1.731
8445        0.02        NaN       NaN          0.0       0.000        0.010
8454        0.45        NaN       NaN         14.8       0.500        0.270
8527        0.36        NaN       NaN          0.0      23.056       28.555
8604         NaN        NaN       NaN          NaN       0.000        0.000

      FA_Poly_(g)  Cholestrl_(mg)
3689        0.222             0.0
4167        0.000             0.0
4169        0.020             0.0
4171        0.000             0.0
4172        0.000             0.0
4173        0.926           205.0
4174        0.167             0.0
4175        1.956             0.0
4177        0.000             0.0
4178        0.000             0.0
4180        0.000             0.0
4185        0.000             0.0
4186        0.000             0.0
4191        0.000             0.0
4164        0.000             0.0
4192        0.021            12.0
4195        0.000             0.0
4197        1.831             0.0
4198        0.000             0.0
4199        0.000             0.0
4200        0.299            16.0
4201        2.701             0.0
4202        0.400             4.0
4206        0.000             0.0
4207        0.000             0.0
4208        0.000             0.0
4209        0.000             0.0
4213        0.000             0.0
4215        0.000             0.0
4194        0.000             0.0
...           ...             ...
8345        2.907             NaN
8350        0.787             1.0
8351        0.310            59.0
8352        0.989             5.0
8353        7.090             NaN
8354        2.317             0.0
8355        2.344             5.0
8356        5.601            16.0
8359        8.142            42.0
8360        8.519            89.0
8361        7.612            67.0
8362        6.833             0.0
8363        0.742            87.0
8364        3.925            16.0
8365        6.548             0.0
8366        5.104            32.0
8367        9.516            83.0
8368        1.010             7.0
8369       10.701            57.0
8370        0.672            82.0
8374        1.984            36.0
8376        7.116            24.0
8377        1.226            16.0
8382        0.512             9.0
8383        0.530             8.0
8384        0.494             9.0
8445        0.010             0.0
8454        0.420            11.0
8527        7.320            67.0
8604        0.000             0.0

[8618 rows x 36 columns]

13.loc

xxx.loc按索引提取单行的数值

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.loc[3])

打印结果:

NDB_No                    1004
Shrt_Desc          CHEESE BLUE
Water_(g)                42.41
Energ_Kcal                 353
Protein_(g)               21.4
Lipid_Tot_(g)            28.74
Ash_(g)                   5.11
Carbohydrt_(g)            2.34
Fiber_TD_(g)                 0
Sugar_Tot_(g)              0.5
Calcium_(mg)               528
Iron_(mg)                 0.31
Magnesium_(mg)              23
Phosphorus_(mg)            387
Potassium_(mg)             256
Sodium_(mg)               1146
Zinc_(mg)                 2.66
Copper_(mg)               0.04
Manganese_(mg)           0.009
Selenium_(mcg)            14.5
Vit_C_(mg)                   0
Thiamin_(mg)             0.029
Riboflavin_(mg)          0.382
Niacin_(mg)              1.016
Vit_B6_(mg)              0.166
Vit_B12_(mcg)             1.22
Vit_A_IU                   721
Vit_A_RAE                  198
Vit_E_(mg)                0.25
Vit_D_mcg                  0.5
Vit_D_IU                    21
Vit_K_(mcg)                2.4
FA_Sat_(g)              18.669
FA_Mono_(g)              7.778
FA_Poly_(g)                0.8
Cholestrl_(mg)              75
Name: 3, dtype: object

14.iloc

xxx.iloc 按索引提取区域行数值

举个例子:

import pandas
food_info = pandas.read_csv("food_info.csv")
print(food_info.iloc[0:5])

打印结果:

   NDB_No                 Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  \
0    1001          BUTTER WITH SALT      15.87         717         0.85
1    1002  BUTTER WHIPPED WITH SALT      15.87         717         0.85
2    1003      BUTTER OIL ANHYDROUS       0.24         876         0.28
3    1004               CHEESE BLUE      42.41         353        21.40
4    1005              CHEESE BRICK      41.11         371        23.24

   Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)  \
0          81.11     2.11            0.06           0.0           0.06
1          81.11     2.11            0.06           0.0           0.06
2          99.48     0.00            0.00           0.0           0.00
3          28.74     5.11            2.34           0.0           0.50
4          29.68     3.18            2.79           0.0           0.51

        ...        Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  \
0       ...          2499.0      684.0        2.32        1.5      60.0
1       ...          2499.0      684.0        2.32        1.5      60.0
2       ...          3069.0      840.0        2.80        1.8      73.0
3       ...           721.0      198.0        0.25        0.5      21.0
4       ...          1080.0      292.0        0.26        0.5      22.0

   Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)
0          7.0      51.368       21.021        3.043           215.0
1          7.0      50.489       23.426        3.012           219.0
2          8.6      61.924       28.732        3.694           256.0
3          2.4      18.669        7.778        0.800            75.0
4          2.5      18.764        8.598        0.784            94.0

[5 rows x 36 columns]

以上是我在运用中所用到的一些函数及用法,欢迎大家指正批评,如果有需要改进的地方,还希望不吝赐教,如果觉得本文对你有用,别忘记关注订阅推荐博主,谢谢大家的支持!!!

扩展阅读

  • pandas用法大全:https://blog.csdn.net/liufang0001/article/details/77856255
  • 十分钟搞定pandas:http://pandas.pydata.org/pandas-docs/stable/10min.html

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏小樱的经验随笔

【正则表达式学习笔记之一】简单认识正则表达式

一、引言   正则表达式是什么东东?   在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要。正则表达式就是用于描述这些规则的工具。换句...

1913
来自专栏赵俊的Java专栏

两数之和

1363
来自专栏逆向技术

逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式

              逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式 一丶了解什么是结构体,以及计算结构体成员的对其值以及总大小(类也是这样算)...

18410
来自专栏racaljk

[数据结构]对链表、栈、队列的总结

你应该发现了一些异常,为什么链表只有node的定义?再来细想一下这三种模型,我们会发现链表其实就是由节点组成的,而栈和队列我们把它视作一个容器,然后可以向里面放...

783
来自专栏Bingo的深度学习杂货店

KMP 算法

题目描述:Leetcode 28. Implement strStr() 之前在 Leetcode 上 AC 的 O(MN) 版本:Q28 Implement ...

3426
来自专栏郭耀华‘s Blog

TensorFlow 使用变量共享

TensorFlow中的变量一般就是模型的参数。当模型复杂的时候共享变量会无比复杂。

681
来自专栏肖洒的博客

刷题问题集合

split()通过指定分隔符对字符串进行切片,如果参数num有指定值,则仅分隔 num 个子字符串. usage; str.split(str=””, num=...

802
来自专栏lzj_learn_note

4-字符串

字段宽度是转换后的值保留的最小字符个数,精度是数字转换结果中应该包含的小数位数或字符串转换后的值所能包含的最大字符个数。

553
来自专栏编程

python奇遇记:深入的了解函数

很久没更新了,抱歉。最近一段时间忙着对付各种考试,现在总算是考完了,继续来聊聊Python。Python中的函数使用def关键字定义,这个大家都知道,而且Pyt...

16010
来自专栏行者常至

001.python科学计算库numpy(上)

版权声明:本文为博主原创文章,允许转载,请标明出处。 https://blog.csdn.net/qwdafedv/article/deta...

562

扫码关注云+社区