Reputation: 669
I am running the following code with a dataset named "mpg_data"
mpg_data.corr(method='pearson').style.format("{:.2}")
As a result I get the data I need as a table. However, when I try to assign these results to a variable, so I can get them as a usable dataframe, doing this:
results = mpg_data.corr(method='pearson').style.format("{:.2}")
As a result I get:
<pandas.formats.style.Styler object at 0x130379e90>
How can I get the correlation result as a usable dataframe?
Upvotes: 0
Views: 678
Reputation: 170
Drop the .style...
results = mpg_data.corr(arguments)
This should return the correlation matrix as a dataframe. If you want to display just two digits, you can actually do this in matplotlib or use .apply()
on the dataframe.
Upvotes: 1
Reputation: 61
You might use the dataframe applymap instead of style.feature:
results = mpg_data.corr(method='pearson').applymap('${:,.2f}'.format)
Upvotes: 0