Pandas is a very important data processing library in Python, and pandas provides a very rich data processing function, which is helpful to machine learning and data preprocessing before data mining.
The following is the recent small usage summary: 1, pandas read the CSV file to obtain the Dataframe type object, which can enrich the execution of data processing. Missing value processing Dropna () or Fillna () 2, dataframe[' name ', ' age '] to get a specified number of columns of data is not possible, need two brackets df=df[[' name ', ' City '] 3, about the missing value of the processing before I summed up the missing value is an empty string, the processing is regular, in the pandas also provides a very friendly function map () to empty strings. 4, the processing of duplicate values can be drop_duplicates () processing 5, dataframe can be used Loc[row] to traverse the row, loc[row][' XXX ' to get the corresponding row number of field values, There is also a Boolean index Df[df.colname>value] 6, GroupBy provides a powerful split-apply-combine (grouping operation) function, can be based on the value of a column for the keyword to group the original data, The results of each grouping are obtained by traversing the grouped results (dataframe)
Groupdf=df.groupby (df[' Key1 '))
for Name,group in groupdf:
print Group # end Group dataframe type Object
# Print Name # name is a grouped keyword
7, Dataframe rebuild the index, sometimes we want to divide the group after each group has no row of the index or the original value, at this time we want to complete the group's current Dataframe reconstruction index, then we directly use Df.reindex will cause data loss
Raw data
The data after grouping
If you rebuild the indexed data with Reindex, you can see that the value is lost after the index changes
To resolve the Rebuild indexing method:
# Dataframe Rebuild Index
Group=group.reset_index (Drop=true)
GROUP=PD. Dataframe (Group)
8, Dataframe delete Row df=df.drop (Labels=row)
References: Jane book, blog