Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use math.log10 function on whole pandas dataframe

I want to take the logarithm of every value in a pandas dataframe. I have tried this but it does not work:

#Reading data from excel and rounding values on 2 decimal places
import math
import pandas as pd

data = pd.read_excel("DataSet.xls").round(2)
log_data= math.log10(data)

It gives me this error:

TypeError: must be real number, not DataFrame

Do you have any idea what to do?

like image 625
taga Avatar asked Mar 06 '19 13:03

taga


People also ask

How do I select top 10 rows in pandas?

pandas.DataFrame.head() In Python's Pandas module, the Dataframe class provides a head() function to fetch top rows from a Dataframe i.e. It returns the first n rows from a dataframe.

How do I get last 10 columns in pandas?

Use iloc[] to select last N columns of pandas dataframe. Use [] to select last N columns of pandas dataframe. Use tail() to select last N columns of pandas dataframe.


Video Answer


1 Answers

Use the numpy version, not math

import numpy as np

np.log10(df)
like image 87
ecortazar Avatar answered Oct 02 '22 13:10

ecortazar