Below for you to share a pandas data samples based on the selection of methods, has a good reference value, I hope to be helpful to everyone. Come and see it together.
Note: The following code is written based on the python3.5.0
Import Pandasfood_info = Pandas.read_csv ("Food_info.csv") #------------------Select the first row of the data sample--------------------print ( FOOD_INFO.LOC[0] #------------------Select 3 to 6 rows of data Samples----------------------print (Food_info.loc[3:6]) #--------------- ---Head selects the first few lines of the data sample------------------print (Food_info.head (2)) #------------------Select the 2,5,10 row of the data sample,-----------the two methods # Print (food_info.loc[[2,5,10]]) #方法一 two_five_ten = [2,5,10] #方法二print (Food_info.loc[two_five_ten]) #---------- --------Select the Ndb_no column of the Data sample--------------------# Ndb_col = food_info["Ndb_no"] #方法一 col_name = "Ndb_no" #方法二ndb_c OL = Food_info[col_name]print (ndb_col) #------------------Select multiple columns of data samples-------------------# zinc_copper = food_info[[" Zinc_ (Mg) "," Copper_ (mg) "]]columns = [" Zinc_ (Mg) "," Copper_ (mg) "]zinc_copper = Food_info[columns]print (zinc_copper) # ---------------------Comprehensive Small example----------------------------col_names = Food_info.columns.tolist () #把所有的行转化成listprint ( col_names) Gram_columns = []for C in Col_names: #遍历col_names, find out all theg) End Position if C.endswith ("(g)"): Gram_columns.append (c) print (gram_columns) GRAM_DF = Food_info[gram_columns] #把所有以 (g) knot The column of the tail is deposited to Gram_dfprint (Gram_df.head (3))