Just use numpy.sqrt() (see docs) on the resulting pd.Series:
import numpy as np
np.sqrt(football[['wins', 'losses']].sum(axis=1))
But there are of course several ways to accomplish the same result - see below for illustration:
df = pd.DataFrame.from_dict(data={'col_1': np.random.randint(low=1, high=10, size=10), 'col_2': np.random.randint(low=1, high=10, size=10)}, orient='index').T
df['sum'] = df[['col_1', 'col_2']].sum(axis=1)
df['np'] = np.sqrt(df[['col_1', 'col_2']].sum(axis=1))
df['apply'] = df[['col_1', 'col_2']].sum(axis=1).apply(np.sqrt)
df['**'] = df[['col_1', 'col_2']].sum(axis=1) ** .5
col_1 col_2 sum np apply **
0 8 3 11 3.316625 3.316625 3.316625
1 4 1 5 2.236068 2.236068 2.236068
2 6 2 8 2.828427 2.828427 2.828427
3 4 1 5 2.236068 2.236068 2.236068
4 4 7 11 3.316625 3.316625 3.316625
5 7 4 11 3.316625 3.316625 3.316625
6 5 5 10 3.162278 3.162278 3.162278
7 1 2 3 1.732051 1.732051 1.732051
8 6 6 12 3.464102 3.464102 3.464102
9 5 7 12 3.464102 3.464102 3.464102
Answer from Stefan on Stack Overflow Top answer 1 of 2
41
Just use numpy.sqrt() (see docs) on the resulting pd.Series:
import numpy as np
np.sqrt(football[['wins', 'losses']].sum(axis=1))
But there are of course several ways to accomplish the same result - see below for illustration:
df = pd.DataFrame.from_dict(data={'col_1': np.random.randint(low=1, high=10, size=10), 'col_2': np.random.randint(low=1, high=10, size=10)}, orient='index').T
df['sum'] = df[['col_1', 'col_2']].sum(axis=1)
df['np'] = np.sqrt(df[['col_1', 'col_2']].sum(axis=1))
df['apply'] = df[['col_1', 'col_2']].sum(axis=1).apply(np.sqrt)
df['**'] = df[['col_1', 'col_2']].sum(axis=1) ** .5
col_1 col_2 sum np apply **
0 8 3 11 3.316625 3.316625 3.316625
1 4 1 5 2.236068 2.236068 2.236068
2 6 2 8 2.828427 2.828427 2.828427
3 4 1 5 2.236068 2.236068 2.236068
4 4 7 11 3.316625 3.316625 3.316625
5 7 4 11 3.316625 3.316625 3.316625
6 5 5 10 3.162278 3.162278 3.162278
7 1 2 3 1.732051 1.732051 1.732051
8 6 6 12 3.464102 3.464102 3.464102
9 5 7 12 3.464102 3.464102 3.464102
2 of 2
36
I'm a personal fan of the built in pandas.DataFrame.pow (docs here). That way you can get roots of various order (like Stefan's last example).
football[['wins','losses']].sum(axis=1).pow(1./2)
Delft Stack
delftstack.com › home › howto › python pandas › pandas square root
How to Apply Square Root Function on a Column of Pandas Data Frame | Delft Stack
February 12, 2025 - Here we have a dictionary containing key-value pairs that will be converted to a Python data frame using pd.DataFrame(), which takes the data and an array of column names as parameters. Then, we add a new column to the data frame, wins+losses, containing the sum of the wins and losses columns. To understand it better, observe the following output. This data frame will be used in the following methods, where we will find the square root of the wins, losses, and wins+losses columns. ... import pandas as pd data = { "years": [2020, 2021, 2022], "teams": ["Bears", "Packers", "Lions"], "wins": [25, 10, 6], "losses": [5, 5, 16], } df = pd.DataFrame(data, columns=["years", "teams", "wins", "losses"]) df["wins+losses"] = df[["wins", "losses"]].sum(axis=1) df["sqrt(wins)"] = df[["wins"]] ** 0.5 df["sqrt(losses)"] = df[["losses"]] ** 0.5 df["sqrt(wins+losses)"] = df[["wins+losses"]] ** 0.5 df
Videos
Medium
medium.com › @whyamit101 › using-pandas-sqrt-effectively-f0ad5d70ff8e
Using pandas sqrt Effectively. The biggest lie in data science? That… | by why amit | Medium
April 12, 2025 - If you attempt to calculate the square root of a negative number in Pandas, it will return NaN, as real square roots are not defined for negative numbers. Can I use pandas sqrt with non-numerical data? No, pandas sqrt is designed for numerical calculations. If you pass non-numeric data, you may encounter errors. Always ensure your data is numeric before applying the function. Is pandas sqrt faster than standard Python sqrt?
LearnDataSci
learndatasci.com › solutions › python-square-root
Python Square Root: Real and Complex – LearnDataSci
Depending on how you want to handle square roots of negatives, handling a ValueError may be preferable. Alternatively, we can avoid this by using cmath.sqrt(), as we'll see in the next section. You can also calculate the square root of negative and complex numbers using the cmath library.
w3resource
w3resource.com › python-exercises › pandas_numpy › pandas_numpy-exercise-10.php
Apply NumPy function to DataFrame column in Python
Next we use the NumPy function np.sqrt() to calculate the square root of each element in the 'Salary' column. The result is assigned to a new column 'Sqrt_Salary'. The updated DataFrame is then printed to the console. ... Previous: Performing element-wise addition in Pandas DataFrame with NumPy array. Next: Calculating correlation matrix for DataFrame in Python...
Pandas
pandas.pydata.org › pandas-docs › version › 0.17.0 › generated › pandas.DataFrame.apply.html
pandas.DataFrame.apply — pandas 0.17.0 documentation
Enter search terms or a module, class or function name · Applies function along input axis of DataFrame
CodeSource
codesource.io › blog › how-to-square-root-the-pandas-column
How to square root the Pandas column | CodeSource
July 22, 2022 - Here, you can see that we have created a Pandas DataFrame that represents students’ names and marks for a particular subject. We will use this example to calculate the square root. ... In this approach, we are going to use the sqrt() that comes with the NumPy. It is a Python library that is used to compute complex scientific calculations.
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.pow.html
pandas.DataFrame.pow — pandas 2.3.3 documentation
Get Exponential power of dataframe and other, element-wise (binary operator pow) · Equivalent to dataframe ** other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rpow
Stratascratch
platform.stratascratch.com › algorithms › 10400-dataframe-square-root-function
StrataScratch - DataFrame Square Root Function
Note: The function should only compute the square root for non-negative numbers (i.e., values greater than or equal to 0). If any value in the DataFrame is negative, the function should return None for that particular value. The input variable df must be a pandas DataFrame.
W3Schools
w3schools.com › python › ref_math_sqrt.asp
Python math.sqrt() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... # Import math Library import math # Return the square root of different numbers print (math.sqrt(9)) print (math.sqrt(25)) print (math.sqrt(16)) Try it Yourself »
Codecademy
codecademy.com › docs › python:pandas › dataframe › .apply()
Python:Pandas | DataFrame | .apply() | Codecademy
May 12, 2023 - x and y apply the calc_sum function to df to calculate the sum of each column. z applies the calc_sum function to df to calculate the sum of each row. l applies the np.sqrt function to df to calculate the square root of each value. m applies ...
Reddit
reddit.com › r/learnpython › what's the better way of taking the square root of a number?
r/learnpython on Reddit: What's the better way of taking the square root of a number?
December 25, 2022 -
For once, I know you can use the math library, and do
math.sqrt(number)
But Python also has the "double asterisk exponentiation syntax", where you could just do
number**0.5
which mathematically should do the same as the sqrt-function.
Now my question is, is it really the same or are there differences?
Top answer 1 of 3
25
Test it! Run a loop of a 100 numbers, trying both methods and storing the results in a Dataframe. Test to see if the result is equal whilst you loop. You could even time each method to see if one is marginally more efficient than the other
2 of 3
8
I assume math.sqrt should be a bit faster because it is specialized; but you shouldn't trust your (or my) feelings and test it if you need the exact answer. It may also change in the future, with different version of Python.
GeeksforGeeks
geeksforgeeks.org › python › numpy-sqrt-in-python
numpy.sqrt() in Python - GeeksforGeeks
July 12, 2025 - Pandas · Practice · Django · Flask · Last Updated : 12 Jul, 2025 · numpy.sqrt() in Python is a function from the NumPy library used to compute the square root of each element in an array or a single number.