create a heatmap of two categorical variablesMaking heatmap from pandas DataFrameHow to merge two dictionaries in a single expression?Are static class variables possible?How can I safely create a nested directory in Python?How to return multiple values from a function?Using global variables in a functionLimiting floats to two decimal pointsHow do I pass a variable by reference?How do I concatenate two lists in Python?Create a dictionary with list comprehension in PythonHow to access environment variable values?
What food production methods would allow a metropolis like New York to become self sufficient
Company stopped paying my salary. What are my options?
What does this quote in Small Gods refer to?
When do you stop "pushing" a book?
Are there variations of the regular runtimes of the Big-O-Notation?
Is a vertical stabiliser needed for straight line flight in a glider?
Why are parallelograms defined as quadrilaterals? What term would encompass polygons with greater than two parallel pairs?
Bigger equation in text-mode math
Two researchers want to work on the same extension to my paper. Who to help?
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Why is the Sun made of light elements only?
How is CoreiX like Corei5, i7 is related to Haswell, Ivy Bridge?
Is every story set in the future "science fiction"?
Detect the first rising edge of 3 input signals
Noob at soldering, can anyone explain why my circuit wont work?
Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?
How to evaluate sum with one million summands?
Can 'sudo apt-get remove [write]' destroy my Ubuntu?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
date to display the EDT time
Why do unstable nuclei form?
What do "KAL." and "A.S." stand for in this inscription?
Passport stamps art, can it be done?
Why was wildfire not used during the Battle of Winterfell?
create a heatmap of two categorical variables
Making heatmap from pandas DataFrameHow to merge two dictionaries in a single expression?Are static class variables possible?How can I safely create a nested directory in Python?How to return multiple values from a function?Using global variables in a functionLimiting floats to two decimal pointsHow do I pass a variable by reference?How do I concatenate two lists in Python?Create a dictionary with list comprehension in PythonHow to access environment variable values?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have the following datasets of three variables:
- df['Score'] Float dummy (1 or 0)
- df['Province'] an object column where each row is a region
- df['Product type'] an object indicating the industry.
I would like to create a jointplot where on the x axis I have the different industries, on the y axis the different provinces and as colours of my jointplot I have the relative frequency of the score.
Something like this.
https://seaborn.pydata.org/examples/hexbin_marginals.html
For the time being, I could only do the following
mean = df.groupby(['Province', 'Product type'])['score'].mean()
But i am not sure how to plot it.
Thanks!
python pandas plot
add a comment |
I have the following datasets of three variables:
- df['Score'] Float dummy (1 or 0)
- df['Province'] an object column where each row is a region
- df['Product type'] an object indicating the industry.
I would like to create a jointplot where on the x axis I have the different industries, on the y axis the different provinces and as colours of my jointplot I have the relative frequency of the score.
Something like this.
https://seaborn.pydata.org/examples/hexbin_marginals.html
For the time being, I could only do the following
mean = df.groupby(['Province', 'Product type'])['score'].mean()
But i am not sure how to plot it.
Thanks!
python pandas plot
1
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17
add a comment |
I have the following datasets of three variables:
- df['Score'] Float dummy (1 or 0)
- df['Province'] an object column where each row is a region
- df['Product type'] an object indicating the industry.
I would like to create a jointplot where on the x axis I have the different industries, on the y axis the different provinces and as colours of my jointplot I have the relative frequency of the score.
Something like this.
https://seaborn.pydata.org/examples/hexbin_marginals.html
For the time being, I could only do the following
mean = df.groupby(['Province', 'Product type'])['score'].mean()
But i am not sure how to plot it.
Thanks!
python pandas plot
I have the following datasets of three variables:
- df['Score'] Float dummy (1 or 0)
- df['Province'] an object column where each row is a region
- df['Product type'] an object indicating the industry.
I would like to create a jointplot where on the x axis I have the different industries, on the y axis the different provinces and as colours of my jointplot I have the relative frequency of the score.
Something like this.
https://seaborn.pydata.org/examples/hexbin_marginals.html
For the time being, I could only do the following
mean = df.groupby(['Province', 'Product type'])['score'].mean()
But i am not sure how to plot it.
Thanks!
python pandas plot
python pandas plot
edited Mar 23 at 10:00
N8888
4561513
4561513
asked Mar 23 at 9:57
Filippo SebastioFilippo Sebastio
19819
19819
1
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17
add a comment |
1
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17
1
1
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17
add a comment |
1 Answer
1
active
oldest
votes
If you are looking for a heatmap, you could use seaborn heatmap
function. However you need to pivot your table first.
Just creating a small example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
score = [1, 1, 1, 0, 1, 0, 0, 0]
provinces = ['Place1' ,'Place2' ,'Place2', 'Place3','Place1', 'Place2','Place3','Place1']
products = ['Product1' ,'Product3' ,'Product2', 'Product2','Product1', 'Product2','Product1','Product1']
df = pd.DataFrame('Province': provinces,
'Product type': products,
'score': score
)
My df
looks like:
'Province''Product type''score'
0 Place1 Product1 1
1 Place2 Product3 1
2 Place2 Product2 1
3 Place3 Product2 0
4 Place1 Product1 1
5 Place2 Product2 0
6 Place3 Product1 0
7 Place1 Product1 0
Then:
df_heatmap = df.pivot_table(values='score',index='Province',columns='Product type',aggfunc=np.mean)
sns.heatmap(df_heatmap,annot=True)
plt.show()
The result is:
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312548%2fcreate-a-heatmap-of-two-categorical-variables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are looking for a heatmap, you could use seaborn heatmap
function. However you need to pivot your table first.
Just creating a small example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
score = [1, 1, 1, 0, 1, 0, 0, 0]
provinces = ['Place1' ,'Place2' ,'Place2', 'Place3','Place1', 'Place2','Place3','Place1']
products = ['Product1' ,'Product3' ,'Product2', 'Product2','Product1', 'Product2','Product1','Product1']
df = pd.DataFrame('Province': provinces,
'Product type': products,
'score': score
)
My df
looks like:
'Province''Product type''score'
0 Place1 Product1 1
1 Place2 Product3 1
2 Place2 Product2 1
3 Place3 Product2 0
4 Place1 Product1 1
5 Place2 Product2 0
6 Place3 Product1 0
7 Place1 Product1 0
Then:
df_heatmap = df.pivot_table(values='score',index='Province',columns='Product type',aggfunc=np.mean)
sns.heatmap(df_heatmap,annot=True)
plt.show()
The result is:
add a comment |
If you are looking for a heatmap, you could use seaborn heatmap
function. However you need to pivot your table first.
Just creating a small example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
score = [1, 1, 1, 0, 1, 0, 0, 0]
provinces = ['Place1' ,'Place2' ,'Place2', 'Place3','Place1', 'Place2','Place3','Place1']
products = ['Product1' ,'Product3' ,'Product2', 'Product2','Product1', 'Product2','Product1','Product1']
df = pd.DataFrame('Province': provinces,
'Product type': products,
'score': score
)
My df
looks like:
'Province''Product type''score'
0 Place1 Product1 1
1 Place2 Product3 1
2 Place2 Product2 1
3 Place3 Product2 0
4 Place1 Product1 1
5 Place2 Product2 0
6 Place3 Product1 0
7 Place1 Product1 0
Then:
df_heatmap = df.pivot_table(values='score',index='Province',columns='Product type',aggfunc=np.mean)
sns.heatmap(df_heatmap,annot=True)
plt.show()
The result is:
add a comment |
If you are looking for a heatmap, you could use seaborn heatmap
function. However you need to pivot your table first.
Just creating a small example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
score = [1, 1, 1, 0, 1, 0, 0, 0]
provinces = ['Place1' ,'Place2' ,'Place2', 'Place3','Place1', 'Place2','Place3','Place1']
products = ['Product1' ,'Product3' ,'Product2', 'Product2','Product1', 'Product2','Product1','Product1']
df = pd.DataFrame('Province': provinces,
'Product type': products,
'score': score
)
My df
looks like:
'Province''Product type''score'
0 Place1 Product1 1
1 Place2 Product3 1
2 Place2 Product2 1
3 Place3 Product2 0
4 Place1 Product1 1
5 Place2 Product2 0
6 Place3 Product1 0
7 Place1 Product1 0
Then:
df_heatmap = df.pivot_table(values='score',index='Province',columns='Product type',aggfunc=np.mean)
sns.heatmap(df_heatmap,annot=True)
plt.show()
The result is:
If you are looking for a heatmap, you could use seaborn heatmap
function. However you need to pivot your table first.
Just creating a small example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
score = [1, 1, 1, 0, 1, 0, 0, 0]
provinces = ['Place1' ,'Place2' ,'Place2', 'Place3','Place1', 'Place2','Place3','Place1']
products = ['Product1' ,'Product3' ,'Product2', 'Product2','Product1', 'Product2','Product1','Product1']
df = pd.DataFrame('Province': provinces,
'Product type': products,
'score': score
)
My df
looks like:
'Province''Product type''score'
0 Place1 Product1 1
1 Place2 Product3 1
2 Place2 Product2 1
3 Place3 Product2 0
4 Place1 Product1 1
5 Place2 Product2 0
6 Place3 Product1 0
7 Place1 Product1 0
Then:
df_heatmap = df.pivot_table(values='score',index='Province',columns='Product type',aggfunc=np.mean)
sns.heatmap(df_heatmap,annot=True)
plt.show()
The result is:
answered Mar 23 at 15:13
vmouffronvmouffron
9016
9016
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312548%2fcreate-a-heatmap-of-two-categorical-variables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Making heatmap from pandas DataFrame
– perl
Mar 23 at 10:17