--2 mapping data processing pandas replace function, map function

2. Mapping

2.1 Mapping Meaningful statements: create a mapping relationship list, the elements and the values of a particular label or string binding
2.2 functions related operations:
2.2.1 the replace () function: Replace elements (DataFrame \ Series of Functions)
A. Function: df.replace (to_replace = None, value = None, InPlace = False, limit = None, REGEX = False, Method = 'PAD')
B. parameter analysis:
to_replace: STR, REGEX, List, dict, Series, int, a float or None, to be replaced value;
value: scalar, dictionaries, lists, str, regular expressions to replace value;
InPlace: True-place modification;
limit: int, limit the number of forward or backward filled;
regex : bool or to_replace same type; regular expressions;
Method: { 'PAD', 'ffill', 'backfill', 'bfill', None}; PAD / ffill: before using a non-missing values to fill in the missing values ; backfill / bfill: a non-missing value with filling the missing values
; None: specify a value to replace the missing value (dEFAULT this embodiment)

C1 to_replace = None, value = None combat:
Replace under specific field value:
Here Insert Picture Description
replacing the value of a specified field:
Here Insert Picture Description
Replace the value specified elements:
Here Insert Picture Description
dictionary: Do not write value, with a dictionary of values replacement:
Here Insert Picture Description
Regularization: replacement canonical form:
Here Insert Picture Description
c2method combat
Here Insert Picture Description
Here Insert Picture Description
Baidu found this article when the replace function pandas replace function uses the summary , written in their case very meticulous, Amway to you, that is not operating diagram, can these two articles read in conjunction.
D. Small Note: DataFrame, you can not use the method and limit parameters
DataFrame replace operation:

  • Alternatively a single value
    • Replace ordinary
    • Alternatively a single specified value column {column labels: replacement value}
  • Multi-value replacement
    • Replace list
    • Replace single dictionary (recommended)

Series replace operation
to replace a single value
ordinary replacement
dictionary to replace
the multi-value replacement
list of alternatives
dictionaries replacement (recommended)
E. practice, I point oh

2.2.2 map () function: the new one (Series function)
A.map Description: x.map (Arg, na_action = None)
---- Map () can be mapped using the dictionary a new data
---- Map ( ) can be used in the expression lambd
---- Map () method can be used, may be a custom method
---- Map () function sum can not be used like, for loop
---- Map (Dictionary ) dictionary key data sufficient to match all, or occurs NaN3
B. parameter analysis:
Arg: function, dict, or Series
na_action: None {, 'the ignore'}
C. combat:
a C1 official small example:.
Here Insert Picture Description
C2.map parameter is a function of:
Here Insert Picture Description
Here Insert Picture Description
C3.map parameter is expression
Here Insert Picture Description
C4.map parameter is a dictionary:
Here Insert Picture Description
2.2.3.transform () and map () is similar to:
A. use the function: x.transform (func, axis = 0 , * args, ** kwargs)
B. analytical parameters:
FUNC: function, str, list or dictionary
axis: {0, or 'index', 1, or 'columns'}, 0 by default; if 0 or 'index': applying a function to each column. If 1 or "column": applying a function to each row
* args: position parameter passed to func
** kwargs: Keyword parameters to be passed to func
C combat:
Here Insert Picture Description
Here Insert Picture Description
D. practice, I point oh

2.2.4 rename () function: the replacement index (DataFrame function)
A. using the function: DataFrame.rename (self, mapper = None , index = None, column = None, axis = None, copy = True, inplace = False, = None Level, errors = 'the ignore')
B. parameter analysis: reference official website
Here Insert Picture Description
C. combat:
official example
Here Insert Picture Description
: E. Summary
function replaces the row index using the rename ()

  • mapper replace all indexes
  • Replace the line index index
  • Replace columns column index
  • multidimensional index level specified dimensions

Editor send: reference to the article content learning materials. White paper for the industry may also be seen by the older generation, in order to avoid misleading knowledge, the article if there is an error, please crossings friend pointed out, the end to learn promptly corrected, see the comments section -

Published 73 original articles · won praise 24 · views 2567

Guess you like

Origin blog.csdn.net/weixin_44943394/article/details/103930234