Question
Can't figure out what's wrong with the code. It wont complete on HackerRank. #Write your code here import pandas as pd import numpy as np
Can't figure out what's wrong with the code. It wont complete on HackerRank.
#Write your code here import pandas as pd import numpy as np
#task 1 heights_A= pd.Series([176.2, 158.4 , 167.6 , 156.2 , 161.4 ]) heights_A.index = ['s1', 's2', 's3', 's4', 's5'] print("the shape of heights_A:",heights_A.shape )
#task 2 weights_A= pd.Series([85.1, 90.2 , 76.8 , 80.4 , 78.9 ]) weights_A.index = ['s1', 's2', 's3', 's4', 's5'] print("the data type of values in weights_A:",weights_A.dtype )
#task 3 df_A = pd.DataFrame({'Student_height': heights_A,'Student_weight':weights_A}, index = weights_A.index) print(df_A.shape)
#task 4 h_mean = 170.0 h_std = 25.0 np.random.seed(100) heights_B = h_std * np.random.randn(5) + h_mean w_mean = 75.0 w_std = 12.0 np.random.seed(100) weights_B = w_std * np.random.randn(5) + w_mean print("heights_B elements : ", heights_B) print("heights_B mean : ", heights_B.mean()) print(" weights_B elements : ", weights_B) print("weights_B mean : ", weights_B.mean())
# Task 5 data = [[155,45],[156,49],[148,46],[152,50],[151,47]] # Raw Height & Weight of 5 students df_B = pd.DataFrame(data,index=['s1','s2','s3','s4','s5'],columns=['Student_height','Student_weight']) print(df_B)
# Task 6 my_panel = pd.Panel(data={'ClassA':df_A, 'ClassB':df_B}) print("Panel p shape: ",my_panel.shape)
1. Python Pandas | 1 | Data Structures in Pandas Task 1 Create a series named heights A with values 176.2, 158.4, 167.6, 156.2, and 161.4. These values represent the height of 5 students of class A. Label each student as s1, s2, s3, s4, and s5. Determine the shape of heights_A and display it. Note: Use the Series method available in the pandas library. Task 2 - Create another series named weights A with values 85.1, 90.2, 76.8, 80.4, and 78 These values represent the weights of 5 students of class A. - Label each student as s1, s2, s3, s4, and s5. - Determine data type of values in weights_A and display it. Note: Use the Series method available in the pandas library. Task 3 - Create a dataframe named df_A, which contains the height and weight of five students namely S1, S2, S3, S4 and s5. - Label the columns as Student_height and Student_weight, respectively. - Display the shape of df_A. Note: Use the DataFrame method in pandas, and also the series heights A, weights_A created in the previous problems. Task 4 - Create another series named heights_B from a 1-D numpy array of 5 elements derived from the normal distribution of mean 170.0 and standard deviation 25.0. Note: Set random seed to 100 before creating the heights_B series. - Create another series named weights_B from a 1-D numpy array of 5 elements derived from the normal distribution of mean 75.0 and standard deviation 12.0. Note: Set random seed to 100 before creating the weights_B series. - Label both series elements as s1, s2, 53, 54 and s5. - Print the mean of series heights_B. Task 5 - Create a dataframe df_B containing the height and weight of students s1, 52, 53, 54 and s5 belonging to class B. - Label the columns as Student_height and Student_weight respectively. - Display the column names of df_B. Note: Use the heights_B and weights_B series created in the above tasks. Task 6 - Create a panel p, containing the previously created two dataframes df_A and df_B. - Label the first dataframe as ClassA, and second as ClassB. - Determine the shape of panel p and display it. Note: Use the Panel method of pandas. Note: (1) The results of preliminary validation doesn't impact final scoring. In- depth scorings are done at a later stage. (2) Print only the values that are mentioned in the tasks. Steps to answer: 1. Select the online IDE. Wait for the installations to complete under the dev-machine tab. 2. In the terminal, type python3 and press enter. If you can get into the python terminal, you are good to go otherwise run Run > Install. [This will install python and required packages for you. There might be some errors during installation. Re-run Run > Install to solve them.] 3. You have to write your code in the prog.py, file. Once you are done you may manually run the file from the terminal and debug it. Run > Run to execute your code. 4. Run Tests [This will execute your file and check for the required output and gives the result of preliminary validations] 5. Once you are ready to submit the solution, click on the Submit buttonStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started