Python is widely used in full-stack, data science and many other fields because of its beautiful interface, vast libraries and best community. I’ll go with data science for now.
What is python?
Everyone will say a definition that is stated in Google and every book, let me use simple words.
It is a general-purpose programming language. This means that Python can be used in various software development not limited to certain areas unlike HTML, CSS and so on.
Before starting Python Interview Questions, let us go through why python for data science?
Python turned out to be one of the hottest languages for data science, it has great data-oriented features and libraries that speed up data processing, data cleaning and various steps.
Let’s get started with the Most Common Python Interview Questions that you’re going to face.
1) Name any 5 data types in python?
Ans: 1. Integer
- String
- Boolean
- Object
- Float
2) What are indexing and slicing?
Ans: Indexing is used to refer to the data rows starting from zero and slicing is used to retrieve the data from a list.
3) How is the global variable different from the local variable?
Ans: Global variable can be used outside the function and used the thought program in any function, unlike local variable ends after the function is done.
4) Difference between tuple and list and mention its symbol?
Ans: Tuple symbol is (), Python symbol is [] Tuple are immutable and list are mutable, List has a variable size and Tuple has fixed size.
Mutable means we can modify the data in a list or can be replaced, whereas in immutable we can’t modify or replace.
5) Which function is used to get the current date?
Ans: To get the current date using python we can use today() function or using DateTime module writing Small code to extract.
6) Convert string into lowercase and uppercase?
Ans: We can use function lowercase() and uppercase().
7) How do you convert one data type to another?
Ans: We can convert using the data type conversion function
For ex: int(),float(),str()
8) Explain the working of return in Function?
Ans: Before that let us understand what is a function in simple meaning.
A function is used whenever we need to perform a repetitive task or we need to use it in the middle.
The program, a return is used to end the execution of the function call and return a copy of the results to global memory from local memory.
Now we will see Python Interview Questions for Data manipulation
Data manipulation is one of the important steps in the Analysis of a dataset there are various tools and libraries, functions.
-
Difference between pandas library and NumPy?
Ans: Numpy library which provides objects for multidimensional arrays, pandas in memory 2d table object called DataFrame.
-
How can we reverse the list?
Ans: We can use function reverse()
-
Reverse the given list without using the in-built function
L1 = [1,2,3,4,5]?
Ans: L1[: :-1]
-
Write down only even numbers from the below list
L1 = [1,2,3,4,5,6,7,8]
Ans: L1[: : 2]
-
Explain the process of EDA for a capstone project that you have worked on?
Ans: It can be based on the project but some basic EDA process is Data cleaning, Data Analysis.
-
How do you find out null values from a dataset?
Ans: By using isnull() function
-
Which function is used when you want to find the sum of a variable using the other 2 categorical variable variables?
Ans: Groupby() function
-
Find out a max of a list without using the inbuilt function.
Ans: We can solve this one using two methods one using indexing and the other using function, ill use indexing so u won’t miss out on this easy one
Ex: We will consider a random list
L1 =[1,4,5,3,6,7]
L1 = L1.sort()
L1[-1]
7
-
Explain loc and iloc?
Ans: Loc is a method that takes only index labels and returns rows or data frame if the index label exists in the caller data frame
Iloc method is used when the index label of a data frame is something other than numeric series of 0,1,2..n
Let me explain in simple terms
Loc: Label based
iloc: numeric based
For example, if we want to filter data using a name or with some condition, we can use loc. We cannot use iloc here, suppose if u want to retrieve specifically a row with index number u can iloc.
-
How is an array different from a list?
Ans: array can be used to calculate complex computation and it is multi-dimensional, whereas a list a two-dimensional, lists are containers for elements having different data types but arrays are used as containers for elements for the same data type.
These are a set of Python Interview Questions for fresher or beginners that can be really helpful before you attend a job interview. All the best, and happy learning.