Question

In: Computer Science

Please use python. Step a: Create two DataFrames df1 and df2 from the following two tables...

Please use python.
Step a: Create two DataFrames df1 and df2 from the following two tables that hold student scores. Each DataFrame has four rows and three columns.

df1:

df2:

Name

Course A

Course B

Name

Course C

Course D

Adam

80

84

Bob

65

72

Bob

74

76

David

85

82

David

78

83

Eva

76

80

Tom

85

82

Tom

90

88

Step b: Join the two DataFrames into df3 so that it only includes the students who appear in both tables. Print df3.

Step c: Set the column 'Name' as the index of df3 using df3.set_index() function. Print the updated df3. You can learn from https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.set_index.html.

Step d: Show the average score of each student in df3.

Solutions

Expert Solution

Code In Python:

import pandas as pd
#Step A : creation of two dataframes
data1 = {'Name':['Adam','Bob','David','Tom'] , 'CourseA':[80,74,78,85], 'CourseB':[84,76,83,82]}
data2 ={'Name':['Bob','David','Eva','Tom'], 'CourseA':[65,85,76,90], 'CourseB':[72,82,80,88]};
df1 = pd.DataFrame(data1);
df2 = pd.DataFrame(data2);
#printing the two dataframes which are created in step A
print(df1)
print(df2)
#Step B: Join the two DataFrames into df3 so that it only includes the students who appear in both tables.
df3 = pd.merge(df1,df2, how ='inner',on = ['Name']);
# print the dataframe created in step B.
print(df3)
#Step c: Set the column 'Name' as the index of df3 using df3.set_index() function.
df3.set_index('Name',inplace=True);
print(df3);
#Step d: Show the average score of each student in df3.
df3=df3.mean(axis = 1,skipna = True);
print(df3)

This is the step wise output of the program:


Related Solutions

Please use an Access database with two tables to answer the following: use an example to...
Please use an Access database with two tables to answer the following: use an example to discuss the difference between a right, left, and inner join. Next, perform the left joint, right joint, and inner joint all on the each of the two tables.
Python: High school assignment, please keep simple In python: Use the following initializer list to create...
Python: High school assignment, please keep simple In python: Use the following initializer list to create an array: twainQuotes = ["I have never let my schooling interfere with my education.", "Get your facts first, and then you can distort them as much as you please.", "If you tell the truth, you don't have to remember anything.", "The secret of getting ahead is getting started.", "Age is an issue of mind over matter. If you don't mind, it doesn't matter. "]...
2.       The next two tables are summaries from a neighborhood survey. Use the information in the tables...
2.       The next two tables are summaries from a neighborhood survey. Use the information in the tables to summarize the results of the survey. Which of the neighborhoods would you consider the lowest income neighborhood? Explain your answer? TABLE 2 CROWN HEIGHTS,   EAST NEW YORK PROSPECT HEIGHTS / FLATBUSH BED-STUY / BUSHWICK INCOME Count % Count % Count % LESS THAN $15,000 45 19.7% 5 7.8% 11 8.3% $15,000 - $24,999 69 30.1% 25 39.1% 38 28.6% $25,000 - $34,999 64...
Please use Python to create a method for a linked list that returns the index of...
Please use Python to create a method for a linked list that returns the index of a lookup value within the linked lust
please do it step by step with the use of formulas , thank you.. The following...
please do it step by step with the use of formulas , thank you.. The following are monthly percentage price changes for four market indexes. Month DJ SP500 1 0.03 0.02 2 0.07 0.06 3 −0.02 −0.01 4 0.01 0.03 5 0.05 0.04 6 −0.06 −0.04 Russ500 Nicky 0.04 0.04 0.10 −0.02 −0.04 0.07 0.03 0.02 0.11 0.02 −0.08 0.06 (17 points) Compute the following. a. Average monthly rate of return for each index b. Standard deviation for each index...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
IN PYTHON create a python program that accepts input from the user in the following sequence:...
IN PYTHON create a python program that accepts input from the user in the following sequence: 1. Planet Name 2. Planet Gravitational Force(g) for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are: 1. planetName 2. planet GravitationalForce(g) A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of...
step by step in python please Madlibs: A children's game where someone is prompted for a...
step by step in python please Madlibs: A children's game where someone is prompted for a series of words of particular types (e.g., nouns, verbs, colors, animals, etc.) and then those words are inserted into a "story" often creating funny outcomes. Write a Madlib program that will prompt a user for the following types of words in this order: Noun, Food, Food, Verb, Adverb, Adjective, Plural Noun, Color, Verb, Verb, Noun, Female Name, Plural Noun Using those inputs, output the...
SHOW STEP BY STEP SPREADSHEET MODEL A furniture manufacturer produces two types of tables – country...
SHOW STEP BY STEP SPREADSHEET MODEL A furniture manufacturer produces two types of tables – country and contemporary – using three types of machines. The time required to produce the tables on each machine is given in the following table: Machine Country Contemporary Total Machine Time Available Per Week Router 2.5 3.0 1,000 Sander 3.5 5.5 2,000 Polisher 2.0 1.0 1,500 Country tables sell for $395 and contemporary tables sell for $515.   Management has determined that at least 25% of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT