Python 1
Python 1
"Hi, my name is [Your Name], and I recently graduated with a degree in AI and Data
Science from [University Name]. During my internship at Maxgen Technologies, I
contributed to multiple data-driven projects where I helped analyze and interpret
large datasets to support business decisions."
Achievement:
"During my internship, I developed a machine learning model that improved the
prediction accuracy of customer behaviour by 15%. This project enhanced the
company’s decision-making process in customer engagement strategies."
Strengths:
"I excel at problem-solving and have a keen eye for detail. My ability to break down
complex data and derive actionable insights has been recognized during my
internship and academic projects."
Projects:
"I’ve worked on various data science projects, including a Credit Risk Prediction
model and a Restaurant Insights Analysis project, where I was able to demonstrate
my skills in data exploration, machine learning, and predictive modelling."
What are the basic data types in Python?
Response: A list in Python is a mutable, ordered collection of elements that can store items of
different data types. You can declare a list using square brackets:
python
Copy code
Response:
Example of a dictionary:
python
Copy code
Response: The if-elif-else structure is used for conditional branching. The if block runs if the
condition is true, the elif block runs if the previous conditions were false but this one is true, and the
else block runs if all previous conditions are false.
python
Copy code
x = 10
if x > 10:
elif x == 10:
print("Equal to 10")
else:
Response: Loops allow repetitive execution of a block of code. Python supports for and while loops.
Example of a for loop:
python
Copy code
for i in range(3):
print(i) # Output: 0 1 2
Response: A function in Python is defined using the def keyword, followed by the function name,
parentheses, and a colon. The function body is indented.
python
Copy code
def greet(name):
python
Copy code
my_string = "Python"
reversed_string = my_string[::-1]
python
Copy code
numbers = [1, 5, 8, 3]
largest = max(numbers)
print(largest) # Output: 8
Response: You can convert the list to a set, which automatically removes duplicates:
python
Copy code
my_list = [1, 2, 2, 3, 4, 4]
unique_list = list(set(my_list))
python
Copy code
my_list = [1, 2, 2, 3, 3, 3]
count = Counter(my_list)
Response: A palindrome is a string that reads the same forward and backward. You can check this by
reversing the string and comparing it with the original:
python
Copy code
def is_palindrome(s):
return s == s[::-1]
Response: List comprehensions provide a concise way to create lists. It consists of an expression
followed by a for statement inside square brackets. Example:
python
Copy code
python
Copy code
i=1
while i <= 3:
print(i) # Output: 1 2 3
i += 1
Response: In Python 3.9+, you can use the union (|) operator:
python
Copy code
dict1 = {'a': 1}
dict2 = {'b': 2}
Response:
Example:
python
Copy code
for i in range(5):
if i == 3:
print(i)
for i in range(5):
if i == 3:
continue # Skips printing 3
print(i)
Pandas:
o Response:
Pandas has two primary data structures:
o Response:
You can create a DataFrame using dictionaries, lists, NumPy arrays, or even another
DataFrame. Here's an example using a dictionary:
python
Copy code
df = pd.DataFrame(data)
o Response:
You can filter rows using boolean indexing. For example, to filter rows where the
'Age' column is greater than 30:
python
Copy code
o Response:
o loc is label-based, meaning you access rows and columns by labels or boolean
conditions.
o iloc is index-based, meaning you access rows and columns by their index positions.
python
Copy code
o Response:
You can group data using the groupby() function and then apply aggregate functions
like sum(), mean(), count(), etc. For example:
python
Copy code
df.groupby('Category')['Sales'].sum()
o Response:
You can handle missing values by using functions like fillna() to replace them, or
dropna() to remove rows/columns with missing values. Example:
python
Copy code
o Response:
You can merge DataFrames using the merge() function, similar to SQL joins. For
example:
python
Copy code
o Response:
python
Copy code
python
Copy code
9. What are descriptive statistics, and how do you calculate them in Pandas?
o Response:
Descriptive statistics summarize the central tendency, dispersion, and shape of a
dataset’s distribution. You can use describe() in Pandas to get a quick summary:
python
Copy code
df.describe()
10. How do you visualize data in Pandas using line plots, bar plots, and histograms?
• Response:
You can use the Pandas built-in plotting functions to visualize data. Examples:
python
Copy code
df['column'].plot.hist() # Histogram
• Response:
Correlation measures the strength of the relationship between two variables. You can
calculate it using corr():
python
Copy code
df.corr()
• Response:
You can handle duplicates by using drop_duplicates(). For example:
python
Copy code
df.drop_duplicates(inplace=True)
• Response:
Data transformation involves converting data into a suitable format for analysis. In Pandas,
you can apply transformations using apply(), map(), replace(), etc. For example, to normalize
a column:
python
Copy code
• Response:
Covariance measures the directional relationship between two variables. You can calculate it
using the cov() function:
python
Copy code
df.cov()
15. What strategies can you use to handle missing data in EDA?
• Response:
You can either:
• Impute missing data using fillna(), replacing NaN with the mean, median, or mode of the
column.
NumPy:
1. What is a NumPy array, and how is it different from a Python list? Answer:
A NumPy array is a multi-dimensional, homogeneous array (meaning all elements are of the
same data type) used for numerical computations. It is different from a Python list because:
o It supports vectorized operations, making it much faster than lists for large datasets.
o Arrays have fixed size and consume less memory due to contiguous allocation.
python
Copy code
import numpy as np
o np.zeros(), np.ones(), or np.random() for arrays filled with zeros, ones, or random
values:
python
Copy code
python
Copy code
print(arr[1:4]) # Output: [2 3 4]
python
Copy code
python
Copy code
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
python
Copy code
import pandas as pd
df = pd.DataFrame(data)
plt.show()
python
Copy code
df.plot(kind='bar')
plt.show()
python
Copy code
python
Copy code
df.drop_duplicates(inplace=True)
python
Copy code
df = pd.read_csv('file.csv')
python
Copy code
df.to_csv('output.csv', index=False)
10. What is data transformation, and how is it done using Pandas or NumPy? Answer:
Data transformation involves altering the data format or scale for analysis. Common
transformations include:
python
Copy code
scaler = MinMaxScaler()
scaled_data = scaler.fit_transform(df[['column']])
11. What is data aggregation, and how do you perform it with Pandas? Answer:
Aggregation involves summarizing data using functions like sum(), mean(), etc. In Pandas,
you can use:
python
Copy code
python
Copy code
python
Copy code
14. How can you scale numerical data using Pandas? Answer:
You can use sklearn’s MinMaxScaler or StandardScaler to scale numerical data.
Example:
python
Copy code
scaler = MinMaxScaler()
df[['scaled_column']] = scaler.fit_transform(df[['column']])
Copy code
df = pd.read_json('file.json')
python
Copy code
df.to_json('output.json')