Question

In: Computer Science

plot this data into a bar graph: PYTHON data=pandas.read_csv(r'data/tv_shows.txt', low_memory=False) print((data)) print((data.columns)) TV Shows : Rating...

plot this data into a bar graph: PYTHON

data=pandas.read_csv(r'data/tv_shows.txt', low_memory=False)

print((data))

print((data.columns))

 TV Shows : Rating
0           ---------------------
1   A Discovery of Witches : 100%
2                    Barry : 100%
3              Unforgotten : 100%
4                      Veep : 98%
5               Killing Eve : 97%
6                  Billions : 96%
7            Les Misérables : 96%
8                 Supergirl : 89%
9          Call the Midwife : 80%
10          Game of Thrones : 77%
11           Now Apocalypse : 77%
12             The Red Line : 69%
13         Lucifer : No Score Yet
14                Chernobyl : 95%
15               Dead to Me : 85%
16           Better Things : 100%
17      Brooklyn Nine-Nine : 100%
18           Tuca & Bertie : 100%
19      State of the Union : 100%
20        The Twilight Zone : 75%
21                  Happy! : 100%
Index(['TV Shows : Rating'], dtype='object')

In [9]:

display(data)

Solutions

Expert Solution

Few modifications in the text file 
1.I changed normal spaces to Tab spaces in each line
2.I changed'Les Misérables' to 'Les Miserables' 

TXT FILE:

TV Shows : Rating
0   ---------------------
1    A Discovery of Witches : 100%
2   Barry : 100%
3   Unforgotten : 100%
4   Veep : 98%
5   Killing Eve : 97%
6   Billions : 96%
7   Les Miserables : 96%
8   Supergirl : 89%
9   Call the Midwife : 80%
10   Game of Thrones : 77%
11   Now Apocalypse : 77%
12   The Red Line : 69%
13   Lucifer : No Score Yet
14   Chernobyl : 95%
15   Dead to Me : 85%
16   Better Things : 100%
17   Brooklyn Nine-Nine : 100%
18   Tuca & Bertie : 100%
19   State of the Union : 100%
20   The Twilight Zone : 75%
21   Happy! : 100%


CODE:

import matplotlib.pyplot as plt 
import csv
import pandas as pd
tvshows = [] #for storing names of tvshows
rating = [] #for storing the ratings
Label = []
with open('asd.txt', mode='r') as csv_file:
    
    data = csv.reader(csv_file,delimiter='\t') #remove tab space in lines
    line_count = 0
    
    for row in data:
        line_count += 1
        if(line_count==1):# if we are on first line then we store the names of X and Y labels
            la = row[0].split(':')
            #print(la)
            Label.append(la[0])
            Label.append(la[1])
        if(len(row)==2) and line_count>2: #this 'if' is to ignore the line '0 -------'
            arr = row[1].split(':') #we split with : as delimiter and store them in arr and row[1] means we are ignoring the 
            #serial number and starting from name of tvshows in each row
            
            tvshows.append(arr[0]) #name of tv shows and arr[1] stores percentage of rating
            
            sarr = arr[1].strip('%')#we removed % for making it easier to plot in bar graph as we require int values
            if sarr == ' No Score Yet': 
                sarr = '0'
            rating.append(int(sarr)) #converting string to int
#now plotting            
plt.figure()
df = pd.DataFrame({'%Rating':rating}, index=tvshows)# first argument takes the number of bar plots(we require only one) and
#second argument takes the variables for which we are plotting
ax = df.plot.bar() #bar graph
plt.xlabel(Label[0]) #xlabel
plt.ylabel(Label[1]) #ylabel
plt.show()



Related Solutions

(b) For a study of TV shows, you obtain the rating, market share, and advertising revenue...
(b) For a study of TV shows, you obtain the rating, market share, and advertising revenue for 95 popular TV shows. Which of these are statistical questions that could be answered from this data set? (Check all that apply.) *Does the market share of TV shows differ based on the gender of viewers? *For all TV shows on network television, what percentage have ratings of 5.0 or lower? *What is the distribution of ratings for the 95 shows in this...
Use python 2.7 & plotly (dash) to draw bar/line graph for below data OrderedDict([('0K', 7.239253544865276), ('PK',...
Use python 2.7 & plotly (dash) to draw bar/line graph for below data OrderedDict([('0K', 7.239253544865276), ('PK', 3.236322216916338), ('1', 6.415793586505012), ('2', 6.020145027564326), ('3', 5.658685936530415), ('4', 5.37435274038192), ('5', 5.1860079887723085), ('6', 5.035941053040876), ('7', 5.1264549715408), ('8', 5.553318856838249), ('9', 12.200551540951867), ('10', 11.195203964258715), ('11', 8.990680759944928), ('12', 12.767287811888968)]) Make sure all keys, especially the 0K & PK, are showing in the x-axis.
A survey on ownership of satellite TV systems shows the following data:                                 
A survey on ownership of satellite TV systems shows the following data:                                                             Region             East Midwest Southwest West Total Currently Own 41 22 19 26 Likely to Purchase 187 94 49 114 Neither 475 533 163 299 Total Complete the table and answer the following: (Write answers either as fractions or as decimals to 4 decimal places.) a) What is the probability that someone is likely to purchase a satellite system? b) What is the probability that...
Deseasonalize the data by calculating the centered moving average. Plot the deseasonalized data on the graph...
Deseasonalize the data by calculating the centered moving average. Plot the deseasonalized data on the graph created in (a). Calculate the seasonal index for each quarter. Write a short explanation of why the results make sense. Period Sales Mar-01 26.84 Jun-01 26.95 Sep-01 32.21 Dec-01 27.30 Mar-02 26.87 Jun-02 29.82 Sep-02 32.34 Dec-02 29.28 Mar-03 30.07 Jun-03 32.40 Sep-03 35.41 Dec-03 32.15 Mar-04 31.84 Jun-04 35.08 Sep-04 37.80 Dec-04 33.46 Mar-05 33.85 Jun-05 36.73 Sep-05 38.09 Dec-05 32.98 Mar-06 32.93...
Consider as SAMPLE data: 52,84,86,91,96,96,98,100,103,105,109. 1) What graph is better - bar graph or histogram? 2)...
Consider as SAMPLE data: 52,84,86,91,96,96,98,100,103,105,109. 1) What graph is better - bar graph or histogram? 2) What's sum of squares? 3) What's sample standard deviation? 4) What's sample variance? Now, consider as POPULATION data: 52,84,86,91,96,96,98,100,103,105,109 (same). 1) What's sum of squares? 2) What's population standard deviation? 3) What's population variance?
python code: Create a phase plot of a damped driven pendulum using odeint. Show a graph...
python code: Create a phase plot of a damped driven pendulum using odeint. Show a graph of angle as a function of time and angular velocity as a function of angle. Show each step in the code.
This is in Python, I am trying to create a new window to print the data...
This is in Python, I am trying to create a new window to print the data to screen, it prints fine in the terminal. I know this is a small segment of my code and its the only portion I am having a problem with. I was wondering if anyone can see what my problem may be. The current issue is NameError: name 'fltVal' is not defined and AttributeError: 'PressureGUI' object has no attribute 'r_count' Any help would be appreciated...
3. (Exercise 3.4) Use the Marriage data from the mosaicData package a) Create a bar plot...
3. (Exercise 3.4) Use the Marriage data from the mosaicData package a) Create a bar plot to show the frequency counts for each race b) Create a histogram to show the age distribution c) What distribution can you see for age? (Use comments to write in your R Markdown file) d) Create a time-series plot to show the delay by ceremony date (Note: you need to create a vector x<-1:98 first, and then create a new data frame with x=x...
How do you graph outliers on a box plot when given a data set of numbers?...
How do you graph outliers on a box plot when given a data set of numbers? I found the median, lower and upper quartile numbers and have already plotted that but how do you plot outliers? Lets say the data is :1 2 3 4 5 6 7 8 9
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT