在Python中以一个折线图的形式显示基于2个非数字和1个数字数据的数据

2024-09-22 20:20:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据集,包括不同年份和月份不同种类贷款的投诉号码。你知道吗

我需要绘制一个折线图,显示投诉的数量与不同的彩色线不同的贷款类型在这段时间。 我的数据如下:

'Year_Month' 'Issue'                                'Complaints_Count'
201601       Can't repay my loan                    100
201601       Dealing with my lender or servicer     220
201601       Getting a loan                         13
201602       Can't repay my loan                    113
201602       Dealing with my lender or servicer     252
201602       Getting a loan                         11
201603       Can't repay my loan                    180
201603       Dealing with my lender or servicer     630
201603       Getting a loan                         7
201604       Can't repay my loan                    237

我的x轴应该是“年\月”,应该在折线图上显示的值存储在“投诉\计数”中。不同的“问题”应该有不同的行。(问题类型将显示在图例中,以确定每行的问题名称)。你知道吗

我在其他地方找不到解决方案,所以如果有人能帮我绘制上述数据,我将不胜感激。你知道吗


Tags: or数据类型myservicewith绘制can
1条回答
网友
1楼 · 发布于 2024-09-22 20:20:53

Seaborn非常适合这种任务。你知道吗

首先,将数据加载到panda数据帧中。例如,如果您有csv格式的数据:

import pandas as pd
df = pd.read_csv(filename.txt)

然后使用seaborn绘制:

sns.factorplot(data=df, x="Year_Month", y="Complaints_Count", hue="Issue")

enter image description here

您可以使用许多选项来调整绘图。查看factorplot()上的full documentation。你知道吗

相关问题 更多 >