Question

The below code will create a data fram for you. You need to first run the...

The below code will create a data fram for you.

You need to first run the below code and then answer the following questions.

# RUN THIS CELL AFTER ADDING YOUR STUDENT NUMBER

import pandas as pd

import numpy as np

my_student_number =

np.random.seed(my_student_number)

df = pd.DataFrame ({'action': ['BUY']*4+['SELL']*4,

                    'A': np.random.randint(20,45,8),

                    'B': np.random.randint(50,100,8),

                    'C': np.random.randint(110,140,8)})

The above df holds the buy/sell prices of three diferent stocks, A, B, and C recorded over a day. By assuming that you have already added your student number to the above code and run it, answer the below questions associated with operations over df.

## (8) Write a python code that returns the maximum stock price for each `action`.

(4) Write a python code that returns the value in the intersection of column 'A' and row index 5.

(4) What does this code do based on the above df?

(4) Write a python program that prints the sum of stocks of type A that are sold- i.e., their action is SELL.

Homework Answers

Answer #1
# RUN THIS CELL AFTER ADDING YOUR STUDENT NUMBER

import pandas as pd

import numpy as np

my_student_number = 20 # REPLACE WITH YOUR STUDENT NUMBER

np.random.seed(my_student_number)

df = pd.DataFrame ({'action': ['BUY']*4+['SELL']*4,

                    'A': np.random.randint(20,45,8),

                    'B': np.random.randint(50,100,8),

                    'C': np.random.randint(110,140,8)})


# Write a python code that returns the maximum stock price for each `action`.

# Creates a new columns with max stock price for that action
df['max_stock'] = df.apply(lambda x : max(x['A'], x['B'], x['C']), axis = 1)
df


# Write a python code that returns the value in the intersection of column 'A' and row index 5.
df.loc[5, 'A']



# PART 3 - WHICH CODE SNIPPET IS TO EXPLAINED IS NOT MENTIONED IN THE QUESTION ITSELF SO SKIPPING IT.



# Write a python program that prints the sum of stocks of type A that are sold- i.e., their action is SELL.
df.loc[df['action'] == 'SELL', 'A'].sum()

  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run) Write...
****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run) Write a program where the user and the program/computer play a number guessing game. The program should prompt the user for a number (between 1 and 100, inclusive) then the program/computer has to guess what the user entered. Keep track of the number of iterations it takes for the computer to guess the number. Sample runs are shown below: Enter number to be guessed: 88...
Write code snippets to do the following. You should write these in a Python editor and...
Write code snippets to do the following. You should write these in a Python editor and test them out as you go. When they work, copy and paste your final code snippet here. Define a function that takes a total bill and the number of people at your table, and prints the amount that each person owes. e.g. divide_bill(100, 5) would produce Each person owes $20 for their meal. e.g. divide_bill(50.25, 4)would produce Each person owes $12.56 for their meal....
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
The code I have written runs but I need it us UDP not TCP. Also I...
The code I have written runs but I need it us UDP not TCP. Also I just need someone to check my work and make sure that it works properly. The python code needs to be run with command line so you can add more than one client. The directions: 1. The chat is performed between 2 clients and not the server. 2. The server will first start up and choose a port number. Then the server prints out its...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately....
Java Code import java.util.Scanner; /** Create two methods as instructed below and then call them appropriately. Hint: Only one of the methods you create needs to be called from the main method. */ public class LandCalculation { public static void main(String[] args) { final int FEET_PER_ACRE = 43560; // Number of feet per acre double tract = 0.0, acres = 0.0; Scanner keyboard = new Scanner(System.in); System.out.print("Enter the tract size: "); tract = keyboard.nextDouble(); // Validate the user's input. while(tract...
I need the actual code for this... I found a similar response but it was not...
I need the actual code for this... I found a similar response but it was not thorough enough. Problem Prerequisites: None Suppose that a scientist is doing some important research work that requires her to use rabbits in her experiments. She starts out with one adult male rabbit and one adult female rabbit. At the end of each month, a pair of adult rabbits produces one pair of offspring, a male and a female. These new offspring will take one...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Provide the following: A list of two functional requirements. A list of two nonfunctional requirements (must...
    asked 7 minutes ago
  • Select a restaurant with which you are familiar and determine the most likely storage management challenge...
    asked 13 minutes ago
  • Proved 3 examples of problems that have surfaced in health and social services from the arrival...
    asked 13 minutes ago
  • A soccer goalie allows a goal on average of 2.3 times per game. Make an estimate...
    asked 13 minutes ago
  • What are some of the similarities and differences associated with caregiver/parental support across these classifications?
    asked 19 minutes ago
  • It is believed that the mean height of middle school students who play basketball on the...
    asked 19 minutes ago
  • Python Indicate whether each statement will evaluate to True or False after running these initializations: a...
    asked 1 hour ago
  • Briefly explain with two examples how traditional leaders in communities can employ the Ubuntu concept for...
    asked 1 hour ago
  • Question 1 Which are two of the four key aspects of hegemony? Group of answer choices...
    asked 2 hours ago
  • A consumer’s preferences are represented by the following utility function: u(x, y) = lnx + 1/2...
    asked 2 hours ago
  • Kingsford Furnishings Company manufactures designer furniture. Kingsford Furnishings uses a job order cost system. Balances on...
    asked 2 hours ago
  • 300 words:      (b) Do you think that it is appropriate for firms like Black Diamond...
    asked 3 hours ago