Plotting From Dataset In Python
This must be very simple but i am not able to figure out how to do it.I am trying to plot the data present in my dataset. Below is my code , import pandas as pd import matplotlib.
Solution 1:
Another option is to replace
plt.scatter(dataset[0],dataset[1])
with
plt.scatter(dataset[[0]],dataset[[1]])
Solution 2:
There are several options, some already mentionned in previous answers,
plt.scatter(dataset['MealNumber'],dataset['TipReceived'])
(as mentioned by @Ankit Malik)plt.scatter(dataset.iloc[:,0],dataset.iloc[:,1])
plt.scatter(dataset[[0]],dataset[[1]])
(as mentioned by @Miriam)
In order for those to work with the data from the question, one should use the delim_whitespace=True
paramter, as otherwise the read-in would not work:
dataset = pd.read_csv('TipsReceivedPerMeal.csv', delim_whitespace=True)
Solution 3:
Just replace:
plt.scatter(dataset[0],dataset[1])
With:
plt.scatter(dataset['MealNumber'],dataset['TipReceived'])
In Pandas columns can either be referenced by name or by column number with iloc.
Post a Comment for "Plotting From Dataset In Python"