Question

In: Computer Science

Question #1 Please specify he output of the following code (2.4) # import the pandas library...

Question #1 Please specify he output of the following code (2.4)
# import the pandas library and aliasing as pd
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(8, 4),
index = ['a','b','c','d','e','f','g','h'], columns = ['A', 'B', 'C', 'D'])

# for getting values with a boolean array
print df.loc['a']>0

Question #2 Please specify the output of the following code (2.2)

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f',
'h'],columns=['one', 'two', 'three'])

df = df.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
print df.dropna(axis=1)

Question #3 Given the following temp.csv (2.1)

S.No,Name,Age,City,Salary
1,Tom,28,Toronto,20000
2,Lee,32,HongKong,3000
3,Steven,43,Bay Area,8300
4,Ram,38,Hyderabad,3900

Please specify what is the output of the following code:

import pandas as pd 

df=pd.read_csv("temp.csv",names=['a','b','c','d','e'],header=0)
print df

Question 4 Please describe what the following code is doing (2.3)

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(10, 4),
      index = pd.date_range('1/1/2000', periods=10),
      columns = ['A', 'B', 'C', 'D'])
print df
r = df.rolling(window=3,min_periods=1)
print r['A'].aggregate(np.sum)

Solutions

Expert Solution

The Solution for 2.4 is: A,B,C,D with random True or False as follows:

=========================RUN-1================

A False
B False
C True
D True
Name: a, dtype: bool

==========================RUN-2=================
A False
B False
C False
D True
Name: a, dtype: bool

==================================================

solution for 2.2

Empty DataFrame
Columns: []
Index: [a, b, c, d, e, f, g, h]

solution for 2.1

header =0 will remove the header of the csv file

a,b,c,d,e column names are used.

SOLUTION FOR 2.3 is:

It will take the date and divide the date in range 1/1/2000 with columns A,B,C,D.

Finally, it sums the A column values and prints as shown in the image above.


Related Solutions

please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Where to Import a library into a given code Digital pins can be used to Analog...
Where to Import a library into a given code Digital pins can be used to Analog pins can be used to AnalogReadSerial: What pins on the Arduino can be assigned as… The Arduino uses what to assign analog values? Examples of a standard Arduino library The Arduino uses a structured programming language-what type Channels of A/D conversion on the Arduino Uno The Arduino correlates temperature readings with what
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
Python Question I have created a dictionary shown below: import pandas as pd records_dict = {'FirstName':...
Python Question I have created a dictionary shown below: import pandas as pd records_dict = {'FirstName': [ 'Jim', 'John', 'Helen'], 'LastName': [ 'Robertson', 'Adams', 'Cooper'], 'Zipcode': [ '21801', '22321-1143', 'edskd-2134'], 'Phone': [ '555-555-5555', '4444444444', '323232'] } I have stored this dictionary in a data frame, like shown below: records = pd.DataFrame(records_dict) print(records) I am able to print the records just fine. My issue is, I want to eliminate, or put a blank space in, the values of the zipcode and...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1,...
All QUESTIONS, PLEASE 5.    What is the output of the following code: int product = 1, i = 6; while (i < 9) {       product = product * i;       i++; } cout << “i is : ” << i << endl; cout << “product is : ” << product << endl; 6.    What is the output of the following code: int product = 1, i = 6;      do {       product = product * i;       i++;...
specify the code to create html with the following content: 1. a paragraph stating, this is...
specify the code to create html with the following content: 1. a paragraph stating, this is an example. 2 image logo.jpg with alternate text ABC Logo below the paragraph created in 1.
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
This question is about java program. Please show the output and the detail code and comment...
This question is about java program. Please show the output and the detail code and comment of the each question and each Class and interface. And the output (the test mthod )must be all the true! Thank you! Question1 Create a class Animal with the following UML specification: +-----------------------+ | Animal | +-----------------------+ | - name: String | +-----------------------+ | + Animal(String name) | | + getName(): String | | + getLegs(): int | | + canFly(): boolean | |...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT