Question

In: Computer Science

Please use python. Step a: Create two dataframes df1 and df2 as follows: import numpy as...

Please use python.
Step a: Create two dataframes df1 and df2 as follows:

import numpy as np

import pandas as pd

rng = np.random.RandomState(100)

df1 = pd.DataFrame(rng.randint(0, 100, (4, 3)), columns=['A', 'B', 'C'])

df2 = pd.DataFrame(rng.randint(0, 100, (3, 4)), columns=['A', 'B', 'C', 'D'])

Step b: Create a new dataframe df which is the summation of df1 and df2;

Step c: Subtract all columns of df by the half of column 'C' in df1; (Remark: the values in df should be updated)

Step d: Replace the NaN in df by 10; (Remark: the values in df should be updated)

Step e: Use df.apply() to calculate the summation of the numbers in each row of df, and show the result. (Remark: the result should be a vector of four values)

Solutions

Expert Solution

PLEASE GIVE A THUMBS UP

import pandas as pd
import numpy as np
rng = np.random.RandomState(100)
df1 = pd.DataFrame(rng.randint(0,100,(4,3)),columns=['A','B','C'])
df2 = pd.DataFrame(rng.randint(0,100,(3,4)),columns=['A','B','C','D'])
print("Data of df1")
print(df1)
print("Data of df2")
print(df2)
df = df1 + df2
print("Data of df")
print(df)
df.loc[:,'A'] = df.loc[:,'A'] - df.loc[:,'C']/2
df.loc[:,'B'] = df.loc[:,'B'] - df.loc[:,'C']/2
df.loc[:,'C'] = df.loc[:,'C'] - df.loc[:,'C']/2
df.loc[:,'D'] = df.loc[:,'D'] - df.loc[:,'C']/2
print("Data of df after subtraction with df1 column 'C'")
print(df)
df = df.replace([None],[10])
print("Data of df after replace NaN by 10")
print(df)
l = df.sum(axis=1)
vec = []
for i in range(4):
   vec.append(l.loc[i])
print("Summation")
print(vec)


Related Solutions

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...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path):...
Please I seek assistance Python Programing import os import numpy as np def generate_assignment_data(expected_grade_file_path, std_dev, output_file_path): """ Retrieve list of students and their expected grade from file, generate a sampled test grade for each student drawn from a Gaussian distribution defined by the student expected grade as mean, and the given standard deviation. If the sample is higher than 100, re-sample. If the sample is lower than 0 or 5 standard deviations below mean, re-sample Write the list of student...
UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)...
UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array) Implement an algorithm to guess a random number that the computer generates. The random number must be an integer between 1 and 1000 (inclusive). For each unsuccessful attempt, the program must let the user know whether to deal with a higher number or more. low. There is no limit on the number of attempts, the game only ends when the user succeeds. The user...
In python import numpy as np Given the array b = np.arange(-6, 4) compute and print...
In python import numpy as np Given the array b = np.arange(-6, 4) compute and print 1.) The array formed by \(bi^2 - 1\), where the \(bi\) are the elements of the array b. 2.) The array formed by multiplying b with the scalar 100. 3.)The array formed by 2.0 b i in reverse order. (Note: the base 2.0 must be a floating point number; for integer values a ValueError: Integers to negative integer powers are not allowed. is raised.)...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
In Python Create customer information system as follows: Python 3 Create customer information system as follows:...
In Python Create customer information system as follows: Python 3 Create customer information system as follows: Ask the user to enter name, phonenumber, email for each customer. Build a dictionary of dictionaries to hold 10 customers with each customer having a unique customer id. (random number generated) Take the keys of the above mentioned dictionary which are customer ids and make a list. Ask the use to enter a customer id and do a binary search to find if the...
Use NumPy to create a My_Array; a 3 by 3 array where in,m = n +...
Use NumPy to create a My_Array; a 3 by 3 array where in,m = n + m. (e.g., the first row first column would be 0+0=0, second row first column would be 1+0=1, etc). complete the following using NumPy: Compute the mean, median, range, and variance of this array Find the inverse or pseudo inverse Find the determinant Perform the following operations on My_Array Create My_1D_Array by reshaping My_Array into a 1-dimensional array Create a new array that is the...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT