Api reference manual DataFrame part of Pandas: https://pandas.pydata.org/pandas-docs/stable/reference/frame.html
Data processing section:
Data to be processed:
Processing requirements: 1.food column, unified case, NaN delete rows 2, 3 ounces taking the absolute value of a negative value, the same four fields food name combining, the combined ounces value before merging them... average value
code show as below:
# - * - Coding: UTF-. 8 - * - Import PANDAS AS PD DF = pd.read_csv ( ' E: /python3Project/11.csv ' ) # Print (DF) DF [ ' Food ' ] = DF [ ' Food ' ] .str.lower () # unified case letters df.dropna (InPlace = True) # remove the missing data recording Print (DF) DF [ ' your hand after awhile ' ] = DF [ ' your hand after awhile ' ] .apply ( the lambda a: ABS (A)) # negative not legal, the absolute value # Print (DF) #Find food duplicate records, find the average packet # Print (DF [ 'food']. Duplicated (Keep = False)) # d_rows DF = [DF [ 'food']. Duplicated (Keep = False)] = # Keep False means the repetition of all the fields are columns to find out food # Print (d_rows) # g_items = d_rows.groupby ( 'food'). mean () # learn groupBy # Print (g_items) # g_items [ 'food '] = g_items.index # effect is a new Food # Print (g_items) # the first occurrence of bacon replaced average df.loc [0, ' your hand after awhile ' ] = DF [DF [ ' Food ' ]. ISIN ([ ' Bacon ' ])]. Mean () [ ' your hand after awhile '] # Delete the second ounce df.drop (df.index [. 4], InPlace = True) Print (DF) df.index = Range (len (DF)) # re-arranged at the row of the index, according to the order of coherence, from small to large Print (DF) # replace Pastrami first appears as mean df.loc [0, ' your hand after awhile ' ] = DF [DF [ ' Food ' ] .isin ([ ' Pastrami ' ])]. Mean () [ ' your hand after awhile ' ] # delete the second Ounce df.drop (df.index [. 4], InPlace = True) Print (DF) df.index = Range (len (DF)) # re-arranged at the row of the index, according to the order of coherence, small to large Print (df)