Docsity

Pytho for data science, Summaries of Database Programming

Toggle sidebar
bg1
NPTEL PYTHON FOR DATA SCIENCE
ASSIGNMENT SOLUTIONS (WEEK 1)
1. The command used to clear console in Spyder is:-
Answer B - %clear โ€“ An easier way to clear the console in Python
2. Which of the following is a valid variable name?
Answer C - โ€˜ram_2โ€™
Alphanumeric is a valid variable name convention in Python. And supports a
special character _ (underscore)
Variable names should not begin or end with underscore even though both are
allowed
3. Python files are saved with extension
Answer A - .py
4. Which of the following statement is invalid?
Answer B - m.n.q = 3500, 3600, 3700
Dot operators are used to access functions in Python, hence it is not used in
naming a variable
5. The command to display an output in Python is:-
Answer A and D โ€“ display() and print()
6. Assignment operator used in Python is: -
Answer D โ€“ โ€œ=โ€ (equal to)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Pytho for data science and more Summaries Database Programming in PDF only on Docsity!

NPTEL PYTHON FOR DATA SCIENCE

ASSIGNMENT SOLUTIONS (WEEK 1)

  1. The command used to clear console in Spyder is:- Answer B - %clear โ€“ An easier way to clear the console in Python
  2. Which of the following is a valid variable name? Answer C - โ€˜ram_2โ€™ Alphanumeric is a valid variable name convention in Python. And supports a special character _ (underscore) Variable names should not begin or end with underscore even though both are allowed
  3. Python files are saved with extension Answer A - .py
  4. Which of the following statement is invalid? Answer B - m.n.q = 3500, 3600, 3700 Dot operators are used to access functions in Python, hence it is not used in naming a variable
  5. The command to display an output in Python is:- Answer A and D โ€“ display() and print()
  6. Assignment operator used in Python is: - Answer D โ€“ โ€œ =โ€ (equal to)
  1. Consider the variables a and b. Values of a and b are 280 and 15 respectively. The operation that will return a remainder is: - Answer B - a%b
  2. Python command used to calculate 25 is given by:- Answer C - 2**
  3. The values of variables p and q are 15 and 3 respectively. What is the value of โ€˜pโ€™ after running the code below? p=q Answer D โ€“ 45*
  1. Which of the following method can be used to initialize multiple variables with a common value? Answer B - Above 2 and 3
  2. What will be the output after the following statements are executed? X= Y= 17 X%=Y print(X) Answer A - 11
  3. What is the command to clear a single variable โ€˜aโ€™ from the variable explorer? Answer C โ€“ del a
  1. Which of the package is used for visualization in Python Answer D โ€“ ggplot, matplotlib, and seaborn are visualization packages for Python
  2. โ€œ not in โ€ belongs to which type of operator in Python? Answer A โ€“ membership Pythonโ€™s membership operators (โ€œinโ€, โ€œnot inโ€) test for membership in a sequence, such as strings, lists, or tuples
  3. โ€œ is not โ€ belongs to which type of operator in Python? Answer B โ€“ identity โ€œisโ€ and โ€œis notโ€ are the two identity operators - compares the memory locations of two objects. โ€œis notโ€ evaluates to false if the variables on either side of the operator point to the same object and true otherwise.
  1. The command used to add elements to a list Answer D - all of the above() append() โ€“ add an item to the end of the list extend() โ€“ extend the list by appending all the items from the iterable insert() โ€“ insert an item at a given position. Create a Stationery list with the below data Prod = ['Pencil', 'Pen', 'Eraser', 'Pencil Box', 'Scale'] Price= [5, 10, 2, 20, 12] Brand = ['Camlin', 'Rotomac', 'Nataraj', 'Camel', 'Apsara'] Stationery = [Prod, Price, Brand]
  2. The command to add โ€œNotebookโ€ as the first element inside the first level of the list โ€œStationeryโ€ is:- Answer B - Stationery[0].insert(0,'Notebook')
  3. Command to replace the element of Brand โ€œCamelโ€ with โ€œCamlinโ€ inside the list is:- Answer C - Stationery[2][3] = "Camlin"
  1. The list โ€œMonthsโ€ is defined as:- Months = ['Jan', 'Mar', 'June', 'Aug', 'June', 'Feb', 'Nov', 'Dec', 'June', 'Apr', 'May', 'June'] Which of the following commands returns the number of occurances of โ€˜Juneโ€™ Answer A Months.count('June')
  2. Choose the correct command to sort them in ascending order Ages = [ โ€™20โ€™, โ€˜26โ€™, โ€˜56โ€™, โ€˜54โ€™, โ€˜32โ€™, โ€˜28โ€™, โ€˜23โ€™, โ€˜99โ€™, โ€˜87โ€™, โ€˜10โ€™, โ€˜65โ€™, โ€˜88โ€™, โ€˜66โ€™, โ€˜48โ€™, โ€˜42โ€™, โ€˜27โ€™, โ€˜33โ€™, โ€˜38โ€™, โ€˜83โ€™, โ€˜94โ€™, โ€˜66โ€™, โ€˜44โ€™] Answer D Both A and B

Answer questions 1 4 and 1 5 using the information given below: Mylist =[โ€˜aโ€™, โ€˜aโ€™, โ€˜bโ€™, โ€˜bโ€™, โ€˜bโ€™, โ€˜cโ€™, โ€˜cโ€™, โ€˜dโ€™, โ€˜eโ€™]

  1. The output of the code: Mylist.index(โ€˜dโ€™) is Answer A โ€“ 7 ( In Python indexing starts at 0)
  2. The output after you run the command Mylist.pop(0) print(Mylist) Answer B - [โ€˜aโ€™, โ€˜bโ€™, โ€˜bโ€™, โ€˜bโ€™, โ€˜cโ€™, โ€˜cโ€™, โ€˜dโ€™, โ€˜eโ€™]
  3. The command to find the number of elements in the following list โ€œNโ€ N = [24, 27, 29, 26, 25, 23, 20] Answer A - len(N) Create a dictionary โ€˜Countryโ€™ that maps the following countries to their capitals respectively: Country India China Japan Qatar Australia State Delhi Beijing Tokyo Doha Sydney
  4. The command to replace โ€œSydneyโ€ with โ€œCanberraโ€ is:- Answer D - Both A and B

Create the following sets X1 and X2 using the data provided below and answer the questions 18 and 19 X1 9 5 6 3 7 8 1 X2 7 1 3 2 0 4 8

  1. The output of X1.intersection(X2) will be Answer B - {1,3,7,8} s
  2. The command X1.symmetric_difference(X2) Answer C - returns elements not common to both sets
  1. The column sum of ๐‘Œ๐‘‡^ is Answer C

NPTEL โ€“ PYTHON FOR DATA SCIENCE

ASSIGNMENT 3 โ€“ SOLUTION

  1. Both read_csv & read_table are used for reading a text file in python. Ans: d
  2. Perhaps the simplest of all plots in the visualization is line plot. The command for line plot is plot ( ). By default, plot ( ) command from the matplotlib library gives a line plot. Ans: a
  3. INPUT: OUTPUT:

Inference: As weight of the car increases, the mpg decreases Ans: a

  1. The plot to show the relationship between two numerical variables is scatter plot. From seaborn library, regplot( ) is used to plot scatter plot. Ans: d
  2. The lmplot( ) function combines regplot() and FacetGrid. It is intended as a convenient interface to plot scatter plots across conditional subsets of a dataset. Ans: c
  3. A box-and-whisker plot shows the visual representation of the statistical five number summary using a method that is a function of the inter-quartile range. Ans: b
  4. INPUT:

OUTPUT:

REFERENCE:

isna( ) or .isnull( ) Ans: d

  1. DataFrame.column_name.dtypes, DataFrame.column_name.ftypes, and DataFrame.column.dtype are used to identify the data type of a column in a dataframe Ans: d
  2. CODE: Ans: a
  3. CODE: There are 15 records missing in the variable TotalCharges Ans: c
  4. The average monthly charge paid by the customer for the services he/she has signed up for is $ 62. CODE : Ans: b
  1. Under the variable Dependents of churn dataframe, there are 6 records that have โ€œ1@#โ€ CODE : Ans: b
  2. The data type of the variable tenure from the churn dataframe is โ€˜Objectโ€™ CODE : Ans: d
  3. Pandas.Dataframe.where(), pandas.Dataframe.replace and numpy.where() can be used to replace โ€˜Fourโ€™ by 4 and โ€˜Oneโ€™ by 1 under the variable โ€œtenureโ€ CODE: Ans: d