2

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.pyplot as plt

dataset = pd.read_csv('TipsReceivedPerMeal.csv')
plt.scatter(dataset[0],dataset[1])
plt.show()

The data in my CSV file is some random data, which specifies what tip a waiter receive at one particular day.

Data in CSV

MealNumber  TipReceived
1                    17
2                    10
3                    5
4                    7
5                    14
6                    25

Thanks in advance for the help.

1
  • what about dataset.plot(x='MealNumber', y = 'TipReceived' ..., kind='scatter). You might want to have a look at searborns facetgrid Commented Mar 14, 2017 at 10:58

3 Answers 3

4

Another option is to replace plt.scatter(dataset[0],dataset[1]) with

plt.scatter(dataset[[0]],dataset[[1]])
Sign up to request clarification or add additional context in comments.

Comments

1

There are several options, some already mentionned in previous answers,

  1. plt.scatter(dataset['MealNumber'],dataset['TipReceived']) (as mentioned by @Ankit Malik)
  2. plt.scatter(dataset.iloc[:,0],dataset.iloc[:,1])
  3. 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)

Comments

1

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.

2 Comments

Mind that dataset.iloc[0] won't work, you'd need dataset.iloc[:,0] instead.
@ImportanceOfBeingErnest, thanks for the comment. I have corrected it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.