简体   繁体   English

Plot 折线图,每行 dataframe 使用 Python

[英]Plot line graph with each row of dataframe using Python

I would like to plot a line showing the ranking of each of these roller coasters as a function of the year that they were ranked.我想 plot 一条线显示这些过山车中的每一个的排名,作为他们排名当年的 function。 For example for the second row (Boulder Dash, I would like a line graph showing the value 1 for 2013-2016, and then 3 and 4 for 2017 and 2018, respectively.例如对于第二行(Boulder Dash,我想要一个折线图,显示 2013-2016 年的值 1,然后分别显示 2017 年和 2018 年的值 3 和 4。

Since the years will be constant for each different coaster, I tried setting the x-axis with: x = range(6) then I would like to plot: plot(x, ranking) for each different roller coaster.由于每个不同的过山车的年份都是恒定的,我尝试将 x 轴设置为:x = range(6) 然后我想为每个不同的过山车设置 plot:plot(x,ranking)。 What I am confused about is how to get those y values (rating) in a format that could be plotted.我感到困惑的是如何以可以绘制的格式获取这些 y 值(评级)。 Roller Coaster DataFrame过山车 DataFrame

Based on the dataframe from the image, I would use seaborn line plot that already implements a hue parameter, but first, reset the Name index and melt the dataframe: Based on the dataframe from the image, I would use seaborn line plot that already implements a hue parameter, but first, reset the Name index and melt the dataframe:

import seaborn as sns

df_melted = df.reset_index().melt(id_vars=['Name'])
sns.lineplot(data = df_melted, x='Year of Rank', y ='value', hue='Name')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM