简体   繁体   中英

hvplot not displaying dynamically

The code below works fine

data_2015=(data[data.Year==2015]
    .groupby("Country")
    ["Country", "Life expectancy "]
    .median()
    .sort_values(by="Life expectancy ", ascending=True))

data_2015.reset_index().hvplot.bar(x="Country", y="Life expectancy ", rot=90,width=2000, height=550, title = "Life Expectancy for ALL Countries for 2015")

but when I try to input data_year dynamically with the code below, the plot does not show

year = input ('Life expectancy ranking of what year between 2000-2015 are you interested in?:  ')

data_year=(data[data.Year==year]
   .groupby(["Country"])
    [["Country", "Life expectancy "]]
    .median()
    .sort_values(by="Life expectancy ", ascending=False))

data_year.reset_index().hvplot.bar(x="Country", y="Life expectancy ", rot=90,width=2100, height=500, title ="Life expectancy ranking of countries in 2015")

what am i missing?

The issue you are facing is due to the input process. When you use input() , the data is read as a string. Convert it to integer using int() and it will work.

Updated code

year = input ('Life expectancy ranking of what year between 2000-2015 are you interested in?:  ')

data_year=(data[data.Year==int(year)]
   .groupby(["Country"])
    [["Country", "Life expectancy "]]
    .median()
    .sort_values(by="Life expectancy ", ascending=False))

data_year.reset_index().hvplot.bar(x="Country", y="Life expectancy ", rot=90,width=2100, height=500, title ="Life expectancy ranking of countries in 2015")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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