0% found this document useful (0 votes)
93 views6 pages

40 NumPy and Pandas Interview Questions With Answers 1740141557

The document provides a comprehensive list of 40 interview questions and answers related to NumPy and Pandas, essential libraries for data analysis in Python. It covers topics such as array creation, data manipulation, and statistical functions, aimed at helping candidates prepare for data science or analytics job interviews. Each question is succinctly answered, making it a useful resource for quick reference.

Uploaded by

Suhas
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)
93 views6 pages

40 NumPy and Pandas Interview Questions With Answers 1740141557

The document provides a comprehensive list of 40 interview questions and answers related to NumPy and Pandas, essential libraries for data analysis in Python. It covers topics such as array creation, data manipulation, and statistical functions, aimed at helping candidates prepare for data science or analytics job interviews. Each question is succinctly answered, making it a useful resource for quick reference.

Uploaded by

Suhas
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
You are on page 1/ 6

LinkedIN Daily BY Rushikesh(Pranav) Kadam

40 Pandas Numpy interview


questions with answers

m
da
Ka
v)
na
ra
(P

Here are 40 Numpy and Pandas interview questions


sh

with answers for candidates:


ke
hi
us
R
NumPy Interview Questions
1. What is NumPy?
NumPy (Numerical Python) is a library for numerical computing in Python. It
provides support for large, multi-dimensional arrays and matrices, along with
mathematical functions to operate on these structures.

2. How do you install NumPy?

m
You can install NumPy using:

da
pip install numpy

Ka
3. How do you create a NumPy array?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])

v)
print(arr) na
4. What are the advantages of NumPy over Python lists?
ra
●​ Faster operations due to optimized C implementation
●​ Uses less memory
(P

●​ Supports vectorized operations


●​ Built-in mathematical functions
sh

5. How do you check the shape and size of a NumPy array?


arr.shape # Returns (rows, columns)
ke

arr.size # Returns total number of elements


hi

6. How do you create an array of zeros and ones?


us

np.zeros((3, 3)) # 3x3 matrix of zeros


np.ones((2, 2)) # 2x2 matrix of ones
R

7. What is the difference between np.arange() and np.linspace()?


●​ np.arange(start, stop, step) generates evenly spaced values within a
range.
●​ np.linspace(start, stop, num) generates a fixed number of points
between start and stop.
Example:

np.arange(1, 10, 2) # Output: [1, 3, 5, 7, 9]


np.linspace(1, 10, 5) # Output: [1, 3.25, 5.5, 7.75, 10]

8. How do you reshape a NumPy array?


arr = np.array([1, 2, 3, 4, 5, 6])
arr.reshape(2, 3) # Converts into 2x3 matrix

m
9. How do you find the mean, median, and standard deviation in
NumPy?

da
np.mean(arr)
np.median(arr)

Ka
np.std(arr)

10. How do you find the maximum and minimum values in a NumPy

v)
array?
arr.max() # Maximum value
na
arr.min() # Minimum value
ra

11. What is the difference between np.dot() and np.matmul()?


(P

●​ np.dot() performs element-wise multiplication for 1D arrays and matrix


multiplication for 2D arrays.
●​ np.matmul() strictly performs matrix multiplication.
sh
ke

12. How do you flatten a NumPy array?


arr.flatten() # Converts multi-dimensional array into a 1D array
hi
us

13. What is broadcasting in NumPy?


R

Broadcasting allows NumPy to perform operations on arrays of different shapes by


automatically expanding their dimensions.

Example:

a = np.array([1, 2, 3])
b = np.array([[1], [2], [3]])
result = a + b # Broadcasting happens here
14. How do you generate random numbers in NumPy?
np.random.rand(3, 3) # Random numbers between 0 and 1
np.random.randint(1, 100, (3, 3)) # Random integers

15. How do you find unique values in a NumPy array?


np.unique(arr)

m
Pandas Interview Questions

da
16. What is Pandas?

Ka
Pandas is a Python library used for data analysis and manipulation. It provides data
structures like Series and DataFrame for handling tabular data.

v)
17. How do you install Pandas?
pip install pandas
na
18. What are the two main data structures in Pandas?
ra

●​ Series: 1D labeled array


(P

●​ DataFrame: 2D labeled table

19. How do you create a Pandas Series?


sh

import pandas as pd
s = pd.Series([1, 2, 3, 4])
ke

print(s)
hi

20. How do you create a Pandas DataFrame?


us

data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}


df = pd.DataFrame(data)
R

21. How do you read data from a CSV file in Pandas?


df = pd.read_csv('data.csv')

22. How do you display the first few rows of a DataFrame?


df.head() # Shows first 5 rows
df.tail() # Shows last 5 rows
23. How do you check for missing values in Pandas?
df.isnull().sum() # Counts missing values in each column

24. How do you fill missing values in Pandas?


df.fillna(0) # Replaces NaN with 0
df.fillna(df.mean()) # Replaces NaN with column mean

m
25. How do you remove duplicate rows in Pandas?
df.drop_duplicates()

da
26. How do you rename columns in Pandas?

Ka
df.rename(columns={'OldName': 'NewName'}, inplace=True)

v)
27. How do you filter data in Pandas?
df[df['Age'] > 25]
na
28. How do you sort a DataFrame in Pandas?
ra

df.sort_values(by='Age', ascending=False)
(P

29. How do you group data in Pandas?


sh

df.groupby('Category').sum()
ke

30. How do you merge two DataFrames in Pandas?


hi

pd.merge(df1, df2, on='key_column')


us

31. What is the difference between loc and iloc?


R

●​ loc[] selects by label


●​ iloc[] selects by index position

32. How do you apply a function to a column in Pandas?


df['Age'] = df['Age'].apply(lambda x: x + 1)
33. How do you reset the index of a DataFrame?
df.reset_index(drop=True)

34. How do you check the data types of each column?


df.dtypes

35. How do you convert a column to datetime format?

m
df['Date'] = pd.to_datetime(df['Date'])

da
36. How do you pivot a DataFrame?

Ka
df.pivot(index='Date', columns='Category', values='Sales')

37. What is the difference between a Series and a DataFrame?

v)
●​ Series: One-dimensional
na
●​ DataFrame: Two-dimensional

38. How do you get summary statistics of a DataFrame?


ra

df.describe()
(P

39. How do you save a DataFrame to a CSV file?


sh

df.to_csv('output.csv', index=False)
ke

40. How do you check memory usage of a DataFrame?


df.memory_usage()
hi
us

These 40 NumPy and Pandas interview questions will help you prepare for your
next Data Science or Data Analytics job interview.
R

You might also like