Pandas数据读取与显示

    xiaoxiao2021-03-25  94

    import pandas as pd food_info = pd.read_csv("D:\\test\\food_info.csv") #此处需要转义 print (type(food_info)) <class 'pandas.core.frame.DataFrame'> first_row = food_info.head() #默认是前5行 print (first_row) first_row = food_info.head(3) #只读前3行 print("..............................................") print (first_row) print("..............................................") print (food_info.columns) #每一列代表什么 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) \ 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 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 ... 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 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 rows x 36 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')
    转载请注明原文地址: https://ju.6miu.com/read-36138.html

    最新回复(0)