Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python Numpy Pandas Interview Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8
At a glance
Powered by AI
Some of the key takeaways from the document are that Python is an easy to code, open source and portable language with many built-in functions and libraries. It allows users to write code in a concise manner using features like functions, lists, dictionaries etc.

Some of the main features of Python include it being easy to code, free and open source software, extensible with a large number of libraries and packages. It is also an interpreted language with dynamic typing.

Literals in Python are raw data assigned to variables or constants while programming. The main types of literals in Python are string literals, numeric literals, boolean literals, literal collections and the special literal None.

Interview Questions

Python Numpy Pandas

Python descriptive

1. What are the key features of Python?


 Easy to code
 Free and Open Source
 Extensible language
 Python is Portable language
 Coding is Easy
 Open source Libraries

2. What are Keywords in Python?


 Python has a set of keywords that are reserved words that cannot be
used as variable names, function names, or any other identifiers

3. What are Literals in Python and Explain about different Literals?


 Literals in Python is defined as the raw data assigned to variables or constants while
programming. We mainly have five types of literals which includes string literals,
numeric literals, boolean literals, literal collections and a special literal None.

4. What are functions in Python?


 A function is a block of code which only runs when it is called. You can pass
data, known as parameters, into a function. A function can return data as a
result.
5. What are the comments and how can you add comments in Python?
 A comment in Python starts with the hash character, # , and extends to the end of
the physical line. A hash character within a string value is not seen as a comment,
though. To be precise, a comment can be written in three ways - entirely on its own line,
next to a statement of code, and as a multi-line comment block

6. What is a dictionary in Python? Give an example


 A Python dictionary is a mapping of unique keys to values.
 Use {} curly brackets to construct the dictionary
 [] square brackets to index it
 Dictionaries are mutable

7. Explain Python List Comprehension


 A list comprehension provides a concise way to create another list
 Using list comprehensions reduces the number of code lines making it.
It look more elegant
 It is possible to use conditions in a list comprehension
 The list comprehension always returns a list

8. What are the different types of operators in Python?


 Arithmetic (+, -, *, /, %, //)
 Logical (and, or, not)
 Relational (>, <, <=,>=, ==,!=)
 Membership (IN, NOT IN)
 Assignment (+=, *=, /=, %=, **=, //=)

9. What is the difference between tuple and dictionary?


 A list is a collection of ordered data.
 A dictionary is an unordered collection of data that stores data in key-
value pairs.

10. What does len() do?


 It returns the length of an object. For example, it can return the number of items in a
list.

11. What is the type () in Python?


 We use the type() function in Python to identify the type of a
specific Python object.

12. What is the usage of split() function?


 to split a given string or a line by specifying one of the substrings of the given string as
the delimiter.

13. What are the built-in types does python provide?


 Binary
 Boolean (True, False)
 Numeric (int, float, complex)
 Mapping (dict)
 Text type (str)

Python Coding

1. How can you concatenate two tuples?


2. In Python how do you convert a string into lowercase?
3. How do you get a list of all the keys in a dictionary?
4. How can you capitalize the first letter of a string?
5. How can you insert an element at a given index in Python?
6. How will you remove duplicate elements from a list?
7. How to remove spaces from a string in Python?

Numpy descriptive

1. Why are python numpy arrays better than lists?


 A list cannot directly handle a mathematical operations, while array can

2. Describe the map function in Python?


 map() function returns a map object(which is an iterator) of the results
after applying the given function to each item of a given iterable (list, tuple
etc.)

3. Generate array of ‘100’ random numbers sampled from a standard normal distribution using
Numpy

4. How to count the occurrence of each value in a numpy array?


 The function of numpy.count()in python aid in the counts for the non-
overlapping occurrence of sub-string in the specified range. The syntax for
phyton numpy.count() function is as follows

5. Does Numpy Support Nan?


 NaN is short for Not a number. It is used to represent entries that are undefined. It is also
used for representing missing values in a dataset.

6. What does ravel() function in numpy do?


 The numpy.ravel() functions returns contiguous flattened array(1D array
with all the input-array elements and with the same type as it). A copy is
made only if needed. 

7. What is the meaning of axis=0 and axis=1?


 Axis = 0 means vertically downwards across rows
 Axis = 1 means horizontally across columns

8. What is numpy and describe its use cases?


 NumPy (Numerical Python) is a linear algebra library in Python.
 NumPy is very useful for performing mathematical and logical
operations on Arrays. It provides an abundance of useful features for
operations on n-arrays and matrices in Python.

9. What Is the Difference Between Matrices and Arrays?


 Arrays can contain greater than or equal to 1 dimensions.
 Matrices contains 2 dimensions in a table like structure.
 array() function can be used to create matrix by specifying the third dimension
to be 1.
 matrix() function however can be used to create at most 2-dimensional
array.
 Arrays are superset of matrices.
 Matrices are a subset, special case of array where dimensions is two.

10. Get the powers of an array values element-wise


 sample_array1 = np.arange(5)
 sample_array2 = np.arange(0, 10, 2)
 power_array = np.power(sample_array1, sample_array2)

11. Write a NumPy program to get true division of the element-wise array inputs
 x = np.arange(5)
 rslt = np.true_divide(x, 4)

Numpy Coding
1. Find out the mean, median and standard deviation of the numpy array
2. How can you initialize a 5*5 numpy arrays with only zeroes?
3. What is vstack() in numpy? Give an example
4. How to remove elements from one array that exist in another?
5. How to sort a numpy array by a specific column in a 2D array?
6. How to reverse a numpy array in the most efficient way?
7. How to calculate percentiles by using numpy?
8. What is the preferred way to check for an empty (zero Element) Array?
9. How can you find the indices of an array where a condition is true?
10. How to find the maximum and minimum value of a given flattened array?
11. Write a NumPy program to calculate the difference between the maximum and the minimum
values of a given array along the second axis.
12. Find median of a numpy flattened array
13. Write a NumPy program to compute the mean, standard deviation, and variance of a given array
along the second axis
14. Calculate covariance matrix between two numpy arrays

Pandas descriptive
1. What is Pandas?
 Pandas is a Python library used for working with data sets. It has functions for
analyzing, cleaning, exploring, and manipulating data.

2. What are dataframes?


 Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous
tabular data structure with labeled axes (rows and columns). A Data frame is a
two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and
columns. 

3. How to combine dataframes in pandas?


 The concat() function in pandas is used to append either columns
or rows from one DataFrame to another. The concat() function does
all the heavy lifting of performing concatenation operations along
an axis while performing optional set logic (union or intersection) of
the indexes (if any) on the other axes.

4. What kind of joins does pandas offer?


 There are mainly five types of Joins in Pandas: Inner Join. Left Outer
Join. Right Outer Join.

5. How to merge dataframes in pandas?


 . merge(),. concat()

6. How to access the first five entries of a dataframe?


 Df.loc[:5]

7. How to access the last five entries of a dataframe?


 Df.loc[:-5]

8. What are the different functions that can be used by grouby in pandas ?

 count() – Number of non-null observations


 sum() – Sum of values
 mean() – Mean of values
 median() – Arithmetic median of values
 min() – Minimum
 max() – Maximum
 mode() – Mode
 std() – Standard deviation
 var() – Variance


9. What is a series in pandas?
 A Pandas Series is like a column in a table. It is a one-dimensional array
holding data of any type.

10. What features make Pandas such a reliable option to store tabular data?
11. What is vectorization in Pandas?
 Vectorization is used to speed up the Python code without using
loop. Using such a function can help in minimizing the running time
of code efficiently.

12. Mention the different types of Data Structures in Pandas


 Series
 DataFrame

13. How to convert pandas dataframe to numpy array?


 To convert Pandas DataFrame to Numpy Array, use the function
DataFrame. to_numpy() . to_numpy() is applied on this DataFrame and the
method returns object of type Numpy ndarray.

14. What is reindexing in pandas?


 Reindexing in Pandas can be used to change the index of rows and
columns of a DataFrame. Indexes can be used with reference to
many index 

15. What is groupby in Pandas?

 Pandas groupby is used for grouping the data according to the


categories and apply a function to the categories. It also helps to
aggregate data efficiently.

Pandas Coding
1. How will you create a series from dict in Pandas?
2. How can we create a copy of the series in Pandas?
3. Write a Pandas program to get the first 5 rows of a given DataFrame
4. Develop a Pandas program to create and display a one-dimensional array-like object containing
an array of data.
5. Write a Python program to convert a Pandas Series to Python list.
6. Develop a Pandas program to add, subtract, multiple and divide two Pandas Series.
7. Develop a Pandas program to compare the elements of the two Pandas Series.
8. Develop a Pandas program to change the data type of a given column or Series.
9. Write a Pandas program to convert Series of lists to one Series
10. Write a Pandas program to create a subset of a given series based on value and condition
11. Develop a Pandas code to alter the order of index in a given series
12. Write a Pandas code to get the items of a given series not present in another given series.
13. What is the difference between the two data series df[‘Name’] and df.loc[:,‘Name’]?
14. Write a Pandas program to display the most frequent value in a given series and replace
everything else as “replaced” in the series.
15. Write a Pandas program to find the positions of numbers that are multiples of 5 of a given series.
16. How will you add a column to a pandas DataFrame?
17. How to iterate over a Pandas DataFrame?
18. What is a Pandas Series and give one example?
19. What is pandas groupby give one example?
20. How to create a dataframe from lists?

A)create an empty dataframe

B)add lists as individuals columns to the list

21. How to create a dataframe from a dictionary and give one example?
22. How to fetch a data entry from a pandas dataframe using a given value in index?
23. How to create a new column in pandas by using values from other columns?
24. How to select columns in pandas and add them to a new dataframe? What if there are two
columns with the same name?
25. How to delete a column or group of columns in pandas? Given the below dataset find the highest
paid player in each college in each team.
Reindexing changes the row labels and column labels of a DataFrame. To reindex means to
conform the data to match a given set of labels along a particular axis.

You might also like