0% found this document useful (0 votes)
6 views30 pages

NPTEL Python Notes

The document provides a comprehensive FAQ section covering various topics related to Python programming, data science, and the use of tools like Spyder and Anaconda. It addresses questions about data types, IDEs, list and tuple operations, and specific Python commands. Additionally, it explains the differences between data science and big data analytics, as well as the importance of version control.

Uploaded by

suriyaa0303
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views30 pages

NPTEL Python Notes

The document provides a comprehensive FAQ section covering various topics related to Python programming, data science, and the use of tools like Spyder and Anaconda. It addresses questions about data types, IDEs, list and tuple operations, and specific Python commands. Additionally, it explains the differences between data science and big data analytics, as well as the importance of version control.

Uploaded by

suriyaa0303
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

FREQUENTLY ASKED QUESTIONS 6. What is the difference between data science and big data analytics?

BASICS OF PYTHON Ans. Data science is a multidisciplinary blend of data inference, algorithm development,
and technology in order to solve analytically complex problems. Big data analytics is the
1. Can we convert ‘​int’ ​into ‘​string’ ​datatype? use of advanced analytic techniques against very large, diverse data sets that include
Ans: Yes, we can convert an ‘​int’ into a ‘​string’ ​datatype, but the vice versa is not always structured, semi-structured and unstructured data, from different sources, and in different
possible. sizes from terabytes to zettabytes.
Example:
7. Where to execute the command ​cd​ to change the working directory? Is it in
command prompt or somewhere else? If it is command prompt how it gets affected
by the Spyder tool?
Ans. You can use the spyder interface itself to set your directory using ​cd​ command. No
need to use the command prompt.

8. What is raw data?


Ans. The data that is not processed for use is called raw data.

9. Can we trace the program that we have written in spyder IDE?


Ans. The history of the codes written in spyder IDE will be available in the ​History log
tab.

2. What is anaconda distribution? 10. What is an IDE and why should we use IDE?
Ans. Anaconda is a free and open-source distribution of the Python and R programming Ans. An IDE stands for ​Integrated Development Environment. I​ t is a software application
languages for scientific computing (data science, machine learning applications, consisting of a cohesive unit of tools required for development. It is designed to simplify
large-scale data processing, predictive analytics, etc.), that aims to simplify package software development. Utilities provided by IDEs include tools for managing, compiling,
management and deployment. deploying and debugging software.

3. Why do we use Spyder? Can we use Pycharm? 11. Can I use a jupyter notebook?
Ans. You can use PyCharm as well. From a teaching point of view Spyder provides a Ans. If you are new to programming, better to use Spyder, if you are experienced, you
very good interface. can use jupyter.

4. What is the maximum number of variables that we can delete using "del a,b,c.....n"? 12. When is the assignment operator ‘==’ used?
Is it many or is there any limit to [Link] variables? Ans. The ‘==’ operator is used to check if the values of the two variables are equal or not,
Ans. There is no limit for deleting the variables. You can delete ‘n’ number of variables if it is equal it will return true or else it will return false.
using del command.
13. There are various editors available like notepad++ , visual studio etc . Why and
5. What is the full form of SAS and SPSS ? where do you use it?
Ans. SAS-Statistical Analysis System & SPSS-Statistical Package for the Social Sciences Ans. Editors are used to run the python program as per your application..
Like spyder is used when you want to observe dataset in data science..
Jupyter is useful when you want to run the python program with its running notes,
storing images links with it etc... 22. How important is precedence in an operator?
Ans. If more than one operator is involved in an expression, Python language has a
14. How can I Clear Console? predefined rule of priority for the operators. This rule of priority of operators is called
I am trying to clear the console (Output). I am trying to use %Clear. But it shows an operator precedence.
error.
Ans. It's %clear(small c). Or else place the cursor in the console window and you can use 23. What is the difference between anaconda software and the syder software?
the shortcut key Ctrl+L from the keyboard. Ans. Anaconda is a tool box. It provides different IDEs. Spyder is one of the many IDEs
that Anaconda provides.
15. What is version control?
Ans. Version control is a system that records changes to a file or set of files over time so 24. What about specifying data type for a variable that is not assigned a value. Should it
that you can recall specific versions later. be specified before hand or will python figure it out as the program progresses.
Ans. Python automatically figures out the datatype of each variable with value assigned
16. Can we either work on pycharm ? to it.
Ans. Pycharm is the advanced version of python. You can use Pycharm if you are
comfortable with it. 25. What is the relation between data science and python
Ans. Python is a programming language.
17. What is the difference between pascal and camel case? Data science is a multidisciplinary blend of data inference, algorithm development, and
Ans. Pascal- capitalizes each word ex: PascalCase technology in order to solve analytically complex problems.
Camel Lower Casing - is similar to pascal case but the first word is not capitalized
Camel Upper Casing - is similar to pascal case but the first word is capitalized 26. How to set the working directory?
There are three ways to set a working directory
18. ​ an we save the file in any format ?
C ● Icon
Ans. You have to save a file in .py format in order to use it later. ● Using library os
● Using command cd
19. How to open multiple files in python spyder? Using Icon:
Ans. Although clicking on the Spyder icon will not allow you to open two instances, you
can open a second instance by simply going to the folder where [Link] is and running
[Link] from the command line.

20. I have an excel sheet that has string values and I need to convert to float. But I'm
getting an error Valueerror: could convert string to float. what to do in such cases?
Ans. Not all string values can be converted to float. String values like '2' can be converted
to float since these are numerical values enclosed between quotes. However if you have a
string value 'ABC' you will not be able to convert them to float.

21. How can I assign values to multiple variables in one instance?


[Link] can assign values to multiple variables at once then you can give as x,y=20,30
Type the following in the console 30. How to coerce objects to new data type?
Using library os: ● Convert the datatype of an object to another
● Syntax: ​datatype(object)
● Changes can be stored in same variable or in different variable

Using command cd:

27. What are the basic data types in Python?

28. How to identify the datatype of an object?


Data type of object can be identified using the command ​type(object)

29. How to verify an object data type?


To verify if an object is of a certain data type the following syntax can be used:
type(object) is datatype
Example:
a = 15
Operators if (type(a) is float):
print ("true")
else:
Unary Operators print ("false") # returns false because the data type of 'a' is 'int' not 'float'

false
+, -, , /, //, * and % are known as operators and these operators can be unary or binary
A unary operator has only one operand
The unary - (minus) operator yields the negation of its numeric argument ‘is not’ operator - evaluates to false if the variables on either side of the operator
The unary + (plus) operator yields its numeric argument unchanged point to the same object and true otherwise
The unary ~ (invert) operator yields the bit-wise inversion of its plain or long integer argument
In [4]:

b = 15.6
Example if (type(b) is not float):
print ("true")
else:
print ("false") # returns false because the data type of 'b' is 'float' not 'int'
The - (minus) operator is used to negate any positive number
false
In [1]:

-15 # in this case the - (minus) operator is acting as a unary operator


Membership Operators
Out[1]:

-15 Membership operators are operators used to validate the membership of a value in a sequence
The membership operators are 'in' and 'not in'
In [2]:

100 - 40 # The -(minus) operator is acting as a binary operator


'in' operator - checks if a value exists in a sequence or not
Out[2]:

60 It evaluates to true if it finds a variable in the specified sequence and false


otherwise

Identity operators In [5]:

Identity operators are used to compare if two objects are same with the same memory location x = [1,2,3,4,5]
They are usually used to determine the data type of a variable
print(4 in x) # returns True because 4 exists in the x
The identity operators are 'is' and 'is not'
True

‘is’ operator - evaluates to true if the variables on either side of the operator
point to the same object and false otherwise ‘not in’ operator - evaluates to true if it does not find a variable in the specified
sequence and false otherwise

In [6]:

y = [1,2,3,4,5]

print(8 not in y) # returns True because 8 doesn't exists in the y

True

localhost:8888/notebooks/Desktop/[Link] 1/3 localhost:8888/notebooks/Desktop/[Link] 2/3


END OF SCRIPT

localhost:8888/notebooks/Desktop/[Link] 3/3
WEEK-2 FAQs

General- FAQs

1. How to install spyder


Ans.
● To install spyder, through – ANACONDA NAVIGATOR, click on the link
below: -
[Link]
● Next choose the version based on the OS:
● Click on the version to download
● Post the download, run the setup file
● Set the path
● Open the ANACONDA NAVIGATOR - ​Launch​ spyder

2. How to download slide lectures?


Ans. You will find the lecture slides under the relevant week.

3. How to download lecture videos?


Ans. You will find the lecture videos under the ​Download Videos​ tab.

Sequence Data Types

1. In a list the sub level component index starts from 0 and the inner level elements
start from 0 or 1…?
Ans. In python indexing starts from 0 to n-1. For sub level as well it starts from 0

2. Like tuple can we find out the length of the list?


Ans. Yes! We can find out the length of the list using ​len()

3. When List_1 is concatenated with List_2 , does the length of the List_1 change?
Ans. The length of the List_1 will not change unless you update it in the existing list. If
we assign it to a new variable length of the list changes depending on the number of
elements.

4. Can we find max and min for a tuple?


Ans.​ ​Yes! We can find maximum and minimum value for a tuple using max() and min()
[Link] the only condition is the values of the tuple should have the same datatype.
5. Is a list mutable or immutable and can its values be changed?. 15. What makes tuples different from lists?
Ans. List is mutable, we can change the value. Ans. In lists you can add, modify and delete the elements.
Once tuple is created you will not be able to modify the elements.
6. ​How does one change the name of the key once assigned?.
Ans. Keys cannot be changed. You need to add a new key with the modified value then 16. Can we update the sub level list directly??ex. id[1]=3.
remove the old one, or create a new dictionary with a new dictionary key. [Link]! you can also do that. It automatically gets updated in the main list

7. ​ o insert an element in a list can we use ​append()​ instead of ​insert()?​


T 17. What is a ​Set?​
Ans. ​append​() can also be used. But it basically adds the element at the end. To add it in Ans. ​Set i​ s a collection which is unordered and unindexed. And it returns no duplicate
the specified position you can use the ​insert().​ members. So when you print the values of Set, you won’t get it in the same order as you
have created.
8. I​ f an element occurs twice or thrice, does ​remove​ method remove all occurrences or
only the first occurrence? 18. Explain ​immutability?​
Ans. ​remove ​method removes only the first occurrence of the value. Ans. Once an object is created you will not be able to modify the elements, that refers to
immutability.
9. Is List a type of Data?
Ans. There are four collection data types in the Python programming language.
List is a collection which is ordered and changeable. Allows duplicate members. 19. We print the combine tuple directly then it'll do any changes in the database ?I
mean it will store the data forever or just will store on a temporary basis?
10. How to change a particular element in tuple ? [Link] tuple will be printed but it will not be updated.
Ans. Tuples are immutable, you cannot modify them once created. You can store the combined tuple in variable for future purpose.

11. ​ an slicing be used on lists or only on tuples?


C
Ans. Slicing can be used in lists as well. 20. ​Can we remove more than one object from a list?
[Link]! We can remove multiple elements. Kindly write a loop and remove the
12. ​ hat if more than 2 words are repeated and we want to remove the word more
W elements.
than 2 so how can we use the​ remove()​?
Ans. Kindly write a loop and execute the statements.
21. How to use insert() in case of negative indexing? Does insert() function have positive
indexing as default?​.
13. Why do we use dict_values? can we get simply the values.
Ans. Dictionary can be accessed by calling the key() or values(). Suppose we want to get [Link] of positive indexing you can also specify the negative indexing value.
only values without dict_values, use the command list(dictionary_name.values())
22. When we use a ​pop​ method whether it will print the pop element or not.
14. ​ hen I created a dictionary, The order in which I am creating and the order in
W Ans. The ​pop()​ method removes the item at the given index and returns the removed
which it prints is different.
item.
Ans. Dictionary will have key value pairs and stored in an unordered manner.
23. What is meant by ​String ​in python?
Ans. A string is a sequence of one or more characters (letters, numbers, symbols) that can 3. How do we know whether it is positive indexing or negative indexing ? Is there any
be either a constant or a variable. Made up of Unicode, strings are immutable sequences command to know about indexing?
Ans. The positive index starts from 0 to n-1 (with positive sign)
Negative indexing is used to access elements from the end of a list
negative indexing starts from -1 to -(n) (with negative sign)
24. ​How to create ​Strings​?
Ans. To create a string, enclose a sequence of characters inside single, double, triple 4. What does ":" mean while accessing the subset of the array?
quotes Example: strSample = 'learning’ Ans. The ​:​ operator slices a part from a sequence object such as list, tuple or string. It
takes two arguments. First is the index of the start of slice and second is index of end
of slice. Both operands are optional. If the first operand is omitted, it is 0 by default.
25. How to print strings? If the second is omitted, it is set to the end of the sequence.
Ans. We can print out strings by simply calling the print() function Example:
a=[1,2,3,4,5,6,7]
26. ​What is ​range()​ in python? a[1:3]
Ans.​ range()​ is a built-in function of Python. It is used when a user needs to perform an [2, 3]
action for a specific number of times.
5. Why do we need to use the axis in insert() and delete() function?
27. ​Where do we use ​range()​ in general? [Link]() function is not available in python only del() is available and there is no
Ans.​ range()​ is commonly used for looping hence, knowledge of the same is key axis in the insert() and del() function.
aspect when dealing with any kind of Python code. The insert() function takes two parameters:
● index - position where an element needs to be inserted
28. ​ ow does ​range()​ work?
H ● element - this is the element to be inserted in the list
Ans. ​range()​ takes mainly three arguments
start: integer starting from which the sequence of integers is to be returned
stop: integer before which the sequence of integers is to be returned del() - The del keyword is used to delete objects. You can pass the variable name with
The range of integers end at stop – 1. the index value inside the braces.
step: integer value which determines the increment between each integer in the sequence
6. ​Why are we using axis while inserting an array?.
Numpy Ans. To insert the new array along row wise we will use axis=0 and to add along
column wise use axis=1.
1. How to access two columns from an array at a time ?
Ans. To access the columns from the array please use the below code
a[:,0:2] ---> to access first and 2nd column

2. To add a new array to an existing array ,I have used the below code
[Link](a,[[10,11,14]],axis=0)
But it added in the end ,why?
Ans. It is due to the ​append f​ unction.
​append a​ dds the value at the end of the array.
FREQUENTLY ASKED QUESTIONS 6. What is the difference between data science and big data analytics?
BASICS OF PYTHON Ans. Data science is a multidisciplinary blend of data inference, algorithm development,
and technology in order to solve analytically complex problems. Big data analytics is the
1. Can we convert ‘​int’ ​into ‘​string’ ​datatype? use of advanced analytic techniques against very large, diverse data sets that include
Ans: Yes, we can convert an ‘​int’ into a ‘​string’ ​datatype, but the vice versa is not always structured, semi-structured and unstructured data, from different sources, and in different
possible. sizes from terabytes to zettabytes.
Example:
7. Where to execute the command ​cd​ to change the working directory? Is it in
command prompt or somewhere else? If it is command prompt how it gets affected
by the Spyder tool?
Ans. You can use the spyder interface itself to set your directory using ​cd​ command. No
need to use the command prompt.

8. What is raw data?


Ans. The data that is not processed for use is called raw data.

9. Can we trace the program that we have written in spyder IDE?


Ans. The history of the codes written in spyder IDE will be available in the ​History log
tab.

2. What is anaconda distribution? 10. What is an IDE and why should we use IDE?
Ans. Anaconda is a free and open-source distribution of the Python and R programming Ans. An IDE stands for ​Integrated Development Environment. I​ t is a software application
languages for scientific computing (data science, machine learning applications, consisting of a cohesive unit of tools required for development. It is designed to simplify
large-scale data processing, predictive analytics, etc.), that aims to simplify package software development. Utilities provided by IDEs include tools for managing, compiling,
management and deployment. deploying and debugging software.

3. Why do we use Spyder? Can we use Pycharm? 11. Can I use a jupyter notebook?
Ans. You can use PyCharm as well. From a teaching point of view Spyder provides a Ans. If you are new to programming, better to use Spyder, if you are experienced, you
very good interface. can use jupyter.

4. What is the maximum number of variables that we can delete using "del a,b,c.....n"? 12. When is the assignment operator ‘==’ used?
Is it many or is there any limit to [Link] variables? Ans. The ‘==’ operator is used to check if the values of the two variables are equal or not,
Ans. There is no limit for deleting the variables. You can delete ‘n’ number of variables if it is equal it will return true or else it will return false.
using del command.
13. There are various editors available like notepad++ , visual studio etc . Why and
5. What is the full form of SAS and SPSS ? where do you use it?
Ans. SAS-Statistical Analysis System & SPSS-Statistical Package for the Social Sciences Ans. Editors are used to run the python program as per your application..
Like spyder is used when you want to observe dataset in data science..
Jupyter is useful when you want to run the python program with its running notes,
storing images links with it etc... 22. How important is precedence in an operator?
Ans. If more than one operator is involved in an expression, Python language has a
14. How can I Clear Console? predefined rule of priority for the operators. This rule of priority of operators is called
I am trying to clear the console (Output). I am trying to use %Clear. But it shows an operator precedence.
error.
Ans. It's %clear(small c). Or else place the cursor in the console window and you can use 23. What is the difference between anaconda software and the syder software?
the shortcut key Ctrl+L from the keyboard. Ans. Anaconda is a tool box. It provides different IDEs. Spyder is one of the many IDEs
that Anaconda provides.
15. What is version control?
Ans. Version control is a system that records changes to a file or set of files over time so 24. What about specifying data type for a variable that is not assigned a value. Should it
that you can recall specific versions later. be specified before hand or will python figure it out as the program progresses.
Ans. Python automatically figures out the datatype of each variable with value assigned
16. Can we either work on pycharm ? to it.
Ans. Pycharm is the advanced version of python. You can use Pycharm if you are
comfortable with it. 25. What is the relation between data science and python
Ans. Python is a programming language.
17. What is the difference between pascal and camel case? Data science is a multidisciplinary blend of data inference, algorithm development, and
Ans. Pascal- capitalizes each word ex: PascalCase technology in order to solve analytically complex problems.
Camel Lower Casing - is similar to pascal case but the first word is not capitalized
Camel Upper Casing - is similar to pascal case but the first word is capitalized 26. How to set the working directory?
There are three ways to set a working directory
18. ​ an we save the file in any format ?
C ● Icon
Ans. You have to save a file in .py format in order to use it later. ● Using library os
● Using command cd
19. How to open multiple files in python spyder? Using Icon:
Ans. Although clicking on the Spyder icon will not allow you to open two instances, you
can open a second instance by simply going to the folder where [Link] is and running
[Link] from the command line.

20. I have an excel sheet that has string values and I need to convert to float. But I'm
getting an error Valueerror: could convert string to float. what to do in such cases?
Ans. Not all string values can be converted to float. String values like '2' can be converted
to float since these are numerical values enclosed between quotes. However if you have a
string value 'ABC' you will not be able to convert them to float.

21. How can I assign values to multiple variables in one instance?


[Link] can assign values to multiple variables at once then you can give as x,y=20,30
Type the following in the console 30. How to coerce objects to new data type?
Using library os: ● Convert the datatype of an object to another
● Syntax: ​datatype(object)
● Changes can be stored in same variable or in different variable

Using command cd:

27. What are the basic data types in Python?

28. How to identify the datatype of an object?


Data type of object can be identified using the command ​type(object)

29. How to verify an object data type?


To verify if an object is of a certain data type the following syntax can be used:
type(object) is datatype
Example:

You might also like