I have pandas dataframe with float columns X and Y and the string column A.
The content of float columns are positive float numbers.
I am extracting the row where column A='a' and another row where column A = 'b'
and I am doing division of float columns of 2 rows (a/b) as in code below.
The problem is that result of division is NaN. Why?
I tried to use axis=0 and axis=1 but result is the same.
I am using python pandas version 1.0.5 Here is my code:
import pandas as pd ddd = { 'A': ['a', 'b'], 'X': [100.0, 20.0], 'Y': [6.0, 2.0] } df = pd.DataFrame(ddd) df1 = df[df['A'] =='a'] df2 = df[df['A'] == 'b'] print(df1) print(df2)` res = df1.iloc[:, 1:].div(df2.iloc[:, 1:], axis=0) print(res) res = df1.iloc[:, 1:].div(df2.iloc[:, 1:], axis=1) print(res) Result
X Y 0 NaN NaN 0 NaN NaN