I'm trying to create a plot for the ranking of each country from 2002 to 2023. I created this dataset by loading each csv file from the respective years, which contains the Countries and Ranking columns, and combining those individual datasets using the Countries column.

Now in this combined dataset, I want to plot a particular country, which shows every rank from 2002 to 2023, using Python. And also, I want to remove decimals from every column; decimals appeared when I used the merge func. to merge all datasets.

Thank You

enter image description here


2 Answers 2


Matplotlib vs Seaborn is a question you will probably get mixed opinions on. I personally use matplotlib because I am most familiar and can do more with it. I think - and take this with a grain of salt - that seaborn is a bit easier to use as a beginner but has more limitations than matplotlib.

For your plotting problem, you should first read up on how to access data in a pandas dataframe:

When you have gathered your data, you can start plotting it:

If you have any specific questions, feel free to ask. But please try to solve your problem yourself first as everything I just posted is readily available through a simple google-search.

Your decimals probably appeared because when you merged the dataframes pandas automatically converted the numerical data from an int type to a float type. If you just want to plot the data, that's not an issue for you. If you still want or need to convert them back to int or similar, you can find help on that here:

  • $\begingroup$ yeah right but i'm actually new in this data analytics i sometimes forget what to use. I will try to read more memorise them. btw thanks for your help $\endgroup$ May 29, 2023 at 10:40

Welcome to datascience.stackexchange Saubhik. First, I'd recommend setting your countries column as the index of the dataframe. Say you start with something like this:

`columns = ["Rank2022", "Rank2023", "Countries"]    
    data = [[1.0, 2.0, "Iceland"], [2.0, 3.0, "Norway"], [3.0, 5.0, "Finland"], [4.0, 6.0, "Sweden"], [5.0, 2.0, "Denmark"]]
    df = pd.DataFrame(data, columns=columns)`

you can set the index to the country column:

df = df.set_index("Countries").

Then you can set the type to int:

df = df.astype(int)

And finally you can plot an individual row with something like:

row = df.loc["Norway"]
  • $\begingroup$ Thanks a lot..... "set_index("Countries")" ,i knew i was missing something thanks a lot for your help. I'm new in data analytics sometimes i don't know what to use. Thanks again $\endgroup$ May 29, 2023 at 10:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.