Issue
I want to plot a line/scatter plot for country name == 'Argentina'
vs its corresponding 'value' only, out of the entire data.
Sample data
This is my code
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("C:/Users/kdandebo/Desktop/Models/Python excercise/Data3.xlsx")
x = (df['Country Name'])
#Although i have figured out x cannot be compared to a string named Argentina, i couldnt think of any other way, Also ive tried the below version too, but none works
#if (df['Country Name'] == 'Argentina'):
# y = (df['Value'])
for x == ("Argentina"):
y = (df['Value'])
plt.scatter(x,y)
plt.show()
Solution
Main problem was reading spread sheet file and selecting the right sheet
import pandas as pd
import matplotlib.pyplot as plt
xl = pd.ExcelFile("Data3.xlsx")
df=xl.parse("Data")
x = df[df['Country Name']=="Argentina"]
plt.scatter(x['Country Name'],x['Value'])
plt.show()
Answered By - Mehrdad Dowlatabadi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.