0

I have a data frame with following columns:

df = pd.read_csv('edtech.csv')
print(df.head())

   Unnamed: 0                                         Title      Date Country  \
0           3     Apple acquires edtech company LearnSprout  15-01-16      US   
1           9  LearnLaunch Accelerator launches new program  15-01-16      US   
2          15                   Flex Class raises financing  15-01-16   India   
3          16               Grovo raises Series C financing  15-01-16      US   
4          17                    Myly raises seed financing  15-01-16   India   

                          Segment  
0             Tools for Educators  
1     Accelerators and Incubators  
2  Adult and Continuing Education  
3               Platforms and LMS  
4                     Mobile Apps  
>>> 

Now, I want to create a scatter plot by mapping 'Country' on one axis and 'Segment' on another. E.g. for US and 'Tools for Educator', there will be one dot on the chart.

How do I convert this dataframe, so that I have numbers, which I can render into a scatter plot? I am able to get the chart in Tableau through count, but don't know the exact working behind the same.

Would be grateful if anyone can help me out. TIA

2
  • What numbers do you want to plot? Country and Segment are catagorical Commented Nov 23, 2016 at 10:37
  • Hi @kezzos I want to plot their count against each other. E.g. US for Tools for Educator, and US for Mobile apps Commented Nov 24, 2016 at 3:35

1 Answer 1

1

I don't know if the possibility of creating a scatter plot with two non-numerical categorical variables exists, the closest I could get to the kind of thing you want is creating counts with groupby, reshaping the data with pivot, and making a heatmap using seaborn:

import pandas as pd
import seaborn as sns

df = pd.read_csv('edtech.csv')
dd = df[['Country','Segment','Title']]
gg = dd.groupby(['Country','Segment'],as_index=False).count().rename(columns={"Title":"Number"})
gp = gg.pivot(columns="Segment",index="Country",values="Number").fillna(0.0)
sns.heatmap(gp,cbar=False)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Khris Though not exactly what I wanted, but it did work. Will create a pivot for count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.