Python | ()

Python Methods and Functions

Syntax : (arg, na_action = None) 


arg: function, dict, or Series

na_action: {None, 'ignore'} If ' ignore ', propagate NA values, without passing them to the mapping correspondence.  na_action checks the NA value and ignores it while mapping in case of 'ignore'

Return type:

 Pandas Series with same as index as caller 

Example # 1:
In the following example, two series are made from the same data. The pokemon_names column and the pokemon_types index column are the same, and therefore () matches the other two columns and returns a new series.

- & gt; 2nd column of caller of map function must be same as index column of passed series.
- & gt;  The values ​​of common column must be unique too.

import pandas as pd

# reading CSV files

pokemon_names = pd.read_csv ( "pokemon.csv" , usecols = [ "Pokemon" ],

squeeze = True )

# usecol is used to use the selected columns
  # index_col is used to make the passed column an ​​index

pokemon_types = pd.read_csv ( "pokemon.csv" , index_col = "Pokemon" ,

squeeze = True )

# using map functions pandas

new = pokemon_names. map (pokemon_types)


print (new)


Example # 2:

This function only works with in series. Passing a data frame will result in an attribute error. Passing streaks with different lengths will result in an output burst of the same length as the caller.

Get Solution for free from DataCamp guru