熊猫Pyplot:计数列散点图
问题描述:
我有以下的列数据帧:熊猫Pyplot:计数列散点图
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
>>>
现在,我想创建一个散点图通过映射“国家”的一轴“细分”另一。例如。对于美国和“教育工具工具”,图表上会有一个点。
如何转换这个数据帧,让我有一个数字,我可以呈现到散点图?我可以通过计数获得Tableau中的图表,但不知道背后的确切工作。
如果有人能帮助我,我将不胜感激。 TIA
答
我不知道是否存在创建具有两个非数值分类变量的散点图的可能性,最接近我可以得到的那种东西是创建计数groupby
,重塑数据pivot
,并使用seaborn
来制作heatmap
:
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)
+0
谢谢@Khris虽然不完全是我想要的,但它确实工作。将为count创建一个关键点 – chhibbz
要绘制哪些数字?国家和细分市场很好笑 – kezzos
Hi @kezzos我想绘制他们对对方的计数。例如。美国为教育工具,美国为移动应用程序 – chhibbz