I understand the usage of map
for a pd.Series
and apply
for a pd.DataFrame
, but what is the difference between using map
and apply
for a pd.Series
? It seems to me that they essentially do the same thing:
>>> df['title'].map( lambda value: str(value) + 'x')
>>> df['title'].apply(lambda value: str(value) + 'x')
It seems both just send a value to a function/map. Is there an actual difference between the two, and if so what would be an example showing it? Or, are these interchangeable when applied to pd.Series
?
For reference, from the docs:
- https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html
- https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.apply.html
For the examples map
uses a dict
and apply
uses a func
, but really, they seem the same? Both can use a function.