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