Question

Write a short python program in the Jupyter notebook using the TIPS dataset. Take a screenshot of your program as shown on yo

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
#Importing pandas Library


# In[2]:


dataset = pd.read_csv("tips.csv")
# Importing dataset into the varaible as pandas dataframe


# In[3]:


dataset["tip_rate"] = dataset["tip"]/dataset["total_bill"]
# Adding new column tip_rate to the dataset by diving tip and total_bill


# In[4]:


import matplotlib.pyplot as plt
# Importing matplotlib library of python to plot the bar graph


# In[5]:


plt.bar(dataset["day"],dataset["tip_rate"])
# Defining x and y varaibles of the graph
plt.xlabel("days")
plt.ylabel("tip_rate")
# Giving label to the bar graph
plt.show()
# Statement to show the plot

Screenshot of output:-

0.7 0.6 0.5 0.4 tip_rate 0.3 0.2 0.1 0.0 Sun Sat Thur Fri dayst:

Screenshots of Code: In [1]: import pandas as pd #Importing pandas Library In [2]: dataset = pd.read_csv(tips.csv) # Importing dataset into the

In [22]: plt.bar(dataset[day], dataset[tip_rate]) # Defining x and y varaibles of the graph plt.xlabel(days) plt.ylabel

Above is the code to calculate display bar graph as asked in the question. The dataset i used was similar to what is asked in question but it has some diffrent values. It would run perfectly on your dataset too.

I have to use this dataset because you haven't provided any dataset.

Explantion:

  • First, we have imported the pandas library of python to get values from the CSV file.
  • After that, the CSV file is read by using the read_csv function of pandas and the value of dataframe is assigned to variable named dataset.
  • After that, a new column named tip_rate is added by dividing tip by total_bill.
  • Then, I have imported matplotlib library of python to plot the bar graph.
  • After that we have plotted the graph using tip_rate and days column of the dataset. Then labels are assigned to x-axis and y-axis.
  • After that plot is displayed which was required.

ScreenShot of the dataset that i used:

B c D E LL G H — time size day Sun Sun 2 3 A 1 (total_bill tip 2 16.99 3 10.34 4 21.01 23.68 24.59 7 25.29 Sun 3 Sun 2 5 6 Su

If there are some doubts you can ask me in comments.

I hope, I'm clear with my answers. Please Upvote

Add a comment
Know the answer?
Add Answer to:
Write a short python program in the Jupyter notebook using the TIPS dataset. Take a screenshot...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program in this Jupyter Notebook. This program will allow a user to choose...

    Write a Python program in this Jupyter Notebook. This program will allow a user to choose from a menu to print various text shapes includeing rectangle, triangle, and diamond as well as a set of numbers in a pattern. This program will allow the user to select the type, the size and/or the fill character for a shape. Your program will verify user inputs such as size for certain range specifications, depending on the shapes.

  • -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer...

    -----------Python program------------------- Instructions: For this assignment, you will write complete a program that allows a customer to plan for retirement. Part 2: Generate a Retirement Planning Table: It's hard to decide how much you need to save for retirement. To help your customer visualize how long her nest egg will last, write a program that allows the user to generate a retirement planning table showing the number of months the savings will last for various combinations of starting account balance...

  • Write, save, and run a Python program that will do the following when run: Let’s consider...

    Write, save, and run a Python program that will do the following when run: Let’s consider the following assignment: a = 1 * 2 + 38 / 8 You want to change the precedence of the operators so that the addition operations are executed first. How would you re-write the assignment? Write a print statement to show the output. Let’s consider the following assignments: x = 'z' y= ['x', 'z', 'q'] Now, apparently x is a member of y. Write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT