0

I have a pandas dataframe (indicators) that includes a column ('ind_df') in which the values are themselves dataframes. I want to multiply the values of one of those dataframes (located in the 'number_of_people_in_poverty' row of the indicators dataframe) by 1,000,000.

type(indicators)
# pandas.core.frame.DataFrame

type(indicators.loc['number_of_people_in_poverty']['ind_df'])
# pandas.core.frame.DataFrame

type(indicators.loc['number_of_people_in_poverty']['ind_df'] * 1000000)
# pandas.core.frame.DataFrame

indicators.loc['number_of_people_in_poverty']['ind_df'] = \
    indicators.loc['number_of_people_in_poverty']['ind_df'] * 1000000

indicators.loc['number_of_people_in_poverty']['ind_df']
# returns unchanged dataframe, not multiplied by 1000000

The operation on the right side of the assignment indeed returns an identical dataframe with all of its values multiplied by 1mil.

But, this dataframe doesn't replace the dataframe on the left side of the assignment. The values in that dataframe remain unchanged.

Why??

Kaleb Coberly
  • 420
  • 1
  • 4
  • 19
  • This seems like a very odd way to use a dataframe. My advice would be to use a dictionary to hold you different dataframes, or, if all of the "sub" dataframes have a common structure, to put them into a single dataframe using a multiindex to reference each "sub" dataframe. I can be more precise if you add a complete minimum working example that would allow me to replicate your problem. – jtorca Oct 27 '20 at 01:20
  • @jtorca, thanks. Yep, I'm using the dictionary, but I wanted to try the dataframe so I could add columns of labels and keep them all together in groupable form. And, yes, I end up combining them in a MultiIndexed df to compare the tables as a whole. If you know a good way to do that, maybe you can provide an answer here? https://stackoverflow.com/questions/64216845/how-to-correlate-scalar-values-of-two-pandas-dataframes – Kaleb Coberly Oct 27 '20 at 06:12
  • But, I also want to keep them in their original 2d forms for easily comparing tables by row or column. Maybe that's a crutch? Is there an easy way to compare tables by row or column when they have been flattened into columns of a MultiIndexed df? Maybe you could add that to your response to the linked post in my last comment? – Kaleb Coberly Oct 27 '20 at 06:15

0 Answers0