Data Science Basics with Python
- 42Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is Anaconda used for in data science?
42 questions
- 1
What is Anaconda used for in data science?
Model answer
Anaconda simplifies setting up a data science environment by managing packages and dependencies.
Explanation
Anaconda is a distribution that includes Python and many data science packages, making installation and environment management easier.
- 2
What VS Code extension provides intellisense, linting, and Jupyter notebook support?
Model answer
The Python extension for VS Code.
Explanation
The Python extension includes features like IntelliSense, linting, and the ability to create and run Jupyter notebooks directly in VS Code.
- 3
What are the two types of cells in a Jupyter notebook?
Model answer
Code cells and Markdown cells.
Explanation
Code cells contain executable code, while Markdown cells are used for annotations and text formatting.
- 4
What is the Rainbow CSV extension used for?
Model answer
It color-codes CSV files to make them easier to read.
Explanation
Rainbow CSV adds syntax highlighting to CSV files, differentiating columns by color.
- 5
How does multiplying a Python list by 2 differ from multiplying a NumPy array by 2?
Model answer
Multiplying a list by 2 duplicates its elements, while multiplying a NumPy array by 2 multiplies each element by 2.
Explanation
In Python, list multiplication repeats the sequence. In NumPy, array multiplication is element-wise, performing scalar multiplication on each entry.
- 6
What is the index of the first element in a Python list or NumPy array?
Model answer
Explanation
Indexing in Python and NumPy starts at 0, so the first element is at position 0.
- 7
How do you access the third element of a NumPy array?
Model answer
By using index 2:
array[2].Explanation
Since indexing starts at 0, the third element is at index 2.
- 8
How can you calculate the mean of a NumPy array?
Model answer
Use the
mean()method:array.mean()ornp.mean(array).Explanation
NumPy provides built-in functions to compute statistical measures like mean.
- 9
How do you get the shape (number of elements) of a NumPy array?
Model answer
Use the
shapeattribute:array.shape.Explanation
The shape attribute returns a tuple with the dimensions of the array.
- 10
If you have a 2D NumPy array created from two arrays, how do you access the first element of the second array?
Model answer
Use
array[1][0]orarray[1, 0].Explanation
The first index selects the second array (index 1), and the second index selects the first element of that array.
- 11
What is a Pandas DataFrame?
Model answer
A DataFrame is a 2D labeled data structure, like a table, with columns of potentially different types.
Explanation
Pandas DataFrames are built on top of NumPy arrays and provide labeled axes (rows and columns) for easier data manipulation.
- 12
How do you create a Pandas DataFrame from a dictionary?
Model answer
pd.DataFrame(dict)where keys become column names and values become column data.Explanation
Pandas can create DataFrames from various data structures; a dictionary is common where each key-value pair represents a column.
- 13
How do you access the first row of a DataFrame using label-based indexing?
Model answer
Use the
locmethod:df.loc[0].Explanation
locaccesses rows by index label. For a DataFrame with default integer index,df.loc[0]returns the first row. - 14
How do you filter rows in a DataFrame where the 'name' column equals 'Vicky'?
Model answer
df[df['name'] == 'Vicky']ordf.query("name == 'Vicky'").Explanation
Boolean indexing uses a condition inside square brackets. The query method allows SQL-like syntax.
- 15
How do you read a CSV file into a Pandas DataFrame?
Model answer
pd.read_csv('filename.csv').Explanation
The
read_csvfunction loads the CSV and automatically infers column headers and data types. - 16
How can you get a count of null values in each column of a DataFrame?
Model answer
df.isnull().sum().Explanation
isnull()returns a boolean DataFrame, andsum()counts True values per column. - 17
How do you fill missing values in a column with the column's mean?
Model answer
df['column'].fillna(df['column'].mean(), inplace=True).Explanation
The
fillnamethod replaces NaN values with the specified value. Settinginplace=Truemodifies the original DataFrame. - 18
How do you drop rows that contain any null values?
Model answer
df.dropna(axis=0).Explanation
dropnaremoves rows (axis=0) that have any missing values. To drop columns, use axis=1. - 19
How do you add a new column to a DataFrame?
Model answer
Assign a Series or list to a new column name:
df['new_col'] = series.Explanation
You can add a column by simply assigning a value to a new column name. The length must match the DataFrame's row count.
- 20
How do you group a DataFrame by a column and compute the mean of another column?
Model answer
df.groupby('group_col')['value_col'].mean().Explanation
groupbysplits the data into groups, and then you can apply an aggregation function likemeanon selected columns. - 21
How do you sort a DataFrame by a column in descending order?
Model answer
df.sort_values(by='column', ascending=False).Explanation
The
sort_valuesmethod sorts by the specified column. Settingascending=Falsegives descending order. - 22
What does the
describe()method return?Model answer
It returns summary statistics including count, mean, std, min, quartiles, and max for each numeric column.
Explanation
describe()provides a quick overview of the distribution of numerical data. - 23
How do you create a basic bar chart using Matplotlib?
Model answer
plt.bar(x_values, heights); plt.show().Explanation
plt.barcreates a bar chart. You need to provide the x-coordinates and the heights of the bars. - 24
How can you rotate x-axis labels in a Matplotlib plot?
Model answer
plt.xticks(rotation=90).Explanation
The
xticksfunction allows setting rotation angle for tick labels. - 25
How do you create subplots (multiple plots in one figure) in Matplotlib?
Model answer
fig, axes = plt.subplots(nrows, ncols)and then plot onaxes[0],axes[1], etc.Explanation
subplotsreturns a figure and an array of axes. You can then call plotting methods on each axes object. - 26
How do you create a pie chart from a Pandas Series of counts?
Model answer
axes.pie(data, labels=labels).Explanation
The
piefunction takes data values and optional labels. It's often used to show proportions. - 27
How can you create a bar chart directly from a Pandas DataFrame without using plt?
Model answer
df.plot(kind='bar', x='col1', y='col2').Explanation
Pandas DataFrames have a built-in
plotmethod that uses Matplotlib under the hood. You specify the kind of plot and columns. - 28
What does a histogram show?
Model answer
It shows the distribution of data by grouping values into bins and displaying the frequency of each bin.
Explanation
Histograms are useful for visualizing the shape and spread of numerical data.
- 29
What does a box plot display?
Model answer
It displays the five-number summary: minimum, first quartile, median, third quartile, and maximum, along with potential outliers.
Explanation
Box plots (box-and-whisker plots) show the spread and skewness of data, with the box representing the interquartile range.
- 30
How do you make a box plot horizontal in Matplotlib?
Model answer
Set
vert=Falsein theboxplotcall.Explanation
By default, box plots are vertical. Setting
vert=Falserotates them horizontally. - 31
What are the three measures of central tendency?
Model answer
Mean, median, and mode.
Explanation
Mean is the average, median is the middle value when sorted, and mode is the most frequent value.
- 32
How do you calculate variance from scratch?
Model answer
Subtract the mean from each data point, square the differences, sum them, and divide by the number of data points.
Explanation
Variance measures how far data points are from the mean. Squaring ensures positive values.
- 33
What is the relationship between variance and standard deviation?
Model answer
Standard deviation is the square root of variance.
Explanation
Standard deviation brings the measure back to the original unit, making it more interpretable.
- 34
In a normal distribution, what percentage of data falls within one standard deviation of the mean?
Model answer
Approximately 68%.
Explanation
This is known as the 68-95-99.7 rule for normal distributions.
- 35
What is the range of a dataset?
Model answer
The difference between the maximum and minimum values.
Explanation
Range gives a simple measure of the spread of data.
- 36
What does a correlation coefficient of 0.91 indicate?
Model answer
A strong positive linear relationship between the two variables.
Explanation
Correlation ranges from -1 to 1. Values close to 1 indicate a strong positive correlation.
- 37
Why is it important to remember that correlation does not imply causation?
Model answer
A high correlation does not prove that one variable causes the other; there could be other factors.
Explanation
Spurious correlations can occur due to chance or confounding variables. Causal relationships require further evidence.
- 38
What is the purpose of min-max scaling?
Model answer
To normalize data to a fixed range, usually [0, 1], by subtracting the minimum and dividing by the range.
Explanation
Min-max scaling allows comparison of variables on different scales by transforming them to a common scale.
- 39
How do you create a scatter plot of study hours vs. grade?
Model answer
plt.scatter(df['study_hours'], df['grade']).Explanation
Scatter plots show the relationship between two numerical variables.
- 40
What is the equation of a linear regression line?
Model answer
y=mx+b, where m is the slope and b is the y-intercept.
Explanation
Linear regression models the relationship between a dependent variable y and independent variable x with a straight line.
- 41
How do you perform linear regression using SciPy?
Model answer
from scipy import stats; slope, intercept, r_value, p_value, std_err = stats.linregress(x, y).Explanation
The
linregressfunction returns the slope and intercept, along with statistical measures like R-squared and p-value. - 42
How do you predict a grade for 14 hours of study using the regression line?
Model answer
Use the equation:
predicted_grade = slope * 14 + intercept.Explanation
With the slope and intercept from linear regression, you can predict y-values for new x-values.

Ask anything
We've read this whole study set, so questions about it get the best answers.