Skip to content Skip to sidebar Skip to footer

Performing Arithmetic Operations On Nested Dataframe Containing A List

I have a dataframe called dailyHistogram defined as follows: dailyHistogram = pd.DataFrame({'NumVisits':[[0 for x in range(1440)] for y in

Solution 1:

That is because NumVisits is a list, and to perform arithmetic on the contents of a list, you need to explicitly apply your functions. For example:

df['NumVisits'].apply(sum)

For element by element sum in each row:

import numpy as np
df['NumVisits'].apply(np.cumsum)

For sum across all rows, for each element in row:

np.array(dailyHistogram['NumVisits'].tolist()).sum(axis=0)

Post a Comment for "Performing Arithmetic Operations On Nested Dataframe Containing A List"