Skip to content
Advertisement

Pandas DataFrame Dividing a column by itself taking first element and divide all the rows and so on

I have a DataFrame from Pandas:

JavaScript

df1:

JavaScript

Now I want to iterate over the rows. For every row, divided by the first elements of the same column and then iterate elements.

Taking all the rows one by one and divided by the first element as standard in the denominator and all rows with second elements and so on.

For example: 1./1., 3./1., 5./1., 2./1. and take next element 1./3., 3./3., 5./3., 2./3. and next, 1./5.,3./5.,5./5.,2./5. and then last 1./2., 3./2., 5./2., 2./2.

and python code works well with for loop.

JavaScript

If I have huge dataset like 15000 rows and I want to implement using applymap() or map()

JavaScript

or

JavaScript

It gives an error for both. Maybe if anyone could help me to optimize my code would appreciate it.

Thanks in advance

Advertisement

Answer

You can use numpy to increase the speed of the process:

JavaScript
JavaScript
JavaScript

Used function and method:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement