Exercise 6 (Operations on DataFrame) 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)
Exercise 6 (Operations on DataFrame)
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
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images