Python pandas and Pythonpandas
Pandas is used for data processing:
Example:
Import pandasfood = pandas. read_csv ("d:/a.csv") # Read the csv file print (food. dtypes) # print (food. head (4) # obtain the first four rows (5 by default) print (food. tail (3) # obtain the last three rows (5 by default) print (food. shape) # print (food. columns) # name of each column
Print (food. loc [1]) # obtain 2nd rows of Data print (food ["name"]) # obtain the column named name
1.
Import pandasfood = pandas. read_csv ("d:/a.csv") list = food. columns. tolist () print (list) # convert all column names to list1 = [] for c in list: if (c. endswith ("(mg)"): list1.append (c) a = food [list1] print (a) # Add the columns ending with (mg) to the new list and complete the processing
2. Sort (Ascending by default)
Import pandasfood = pandas. read_csv ("d:/a.csv") food. sort_values ("Calcium _ (mg)", inplace = True, ascending = False) # sort in descending order, the first column name, the third parameter, and the third parameter in ascending order, the default value is trueprint (food ["Calcium _ (mg)"]).
3.
Import pandasman = pandas. read_csv ("d:/t.csv") print (man) age = man ["Age"] # Age column age_null = age [pandas. isnull (man ["Age"])] # age_null_len = len (age_null) # sum of empty Age