Python

The Python questions and answers in this lesson will help you understand the types of Python questions you can expect in data science interviews.

What is a Python tuple, and how does it differ from a list?

A tuple is a sequence of elements that can be a numeric value, date, character, etc. A tuple is different from a list because it can't be edited, but a list can be edited. We can completely delete a tuple but not add or delete an element in the tuple. Also, the tuple uses round brackets, and the list uses square brackets.

What is the main difference between a pandas Series and a single-column DataFrame in Python?

A single-column DataFrame looks similar to a pandas Series but has rows and columns. On the other hand, a pandas Series is represented by a single column. If we want to apply a pandas Series method on a single column of a DataFrame, it must be converted into a pandas Series. This is the main difference between a single-column DataFrame and a pandas Series.

What is the command to sort a NumPy array by the (n-1)th column?

We can sort a NumPy array using the argsort function. Suppose we have an array x, and we want to sort the (n-1)th column of x. Then the command for sorting would look like this:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.