Menu Close

How to use the apply() function for a single column with Python Pandas?

Sometimes, we want to use the apply() function for a single column with Python Pandas.

In this article, we’ll look at how to use the apply() function for a single column with Python Pandas.

How to use the apply() function for a single column with Python Pandas?

To use the apply() function for a single column with Python Pandas, we can call apply with a lambda function.

For instance, we write

df['a'] = df['a'].apply(lambda x: x + 1)

to call apply on the column a on data frame df with a function that adds 1 to each entry in column a.

Then we assign the retuned values back to column a.

Conclusion

To use the apply() function for a single column with Python Pandas, we can call apply with a lambda function.

Posted in Python, Python Answers