Python Flashcards

1
Q

What is the correct syntax for reshape() function in NumPy?

A

reshape(array, shape)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different ways to create a data frame in Pandas?

A
  1. By initializing a list
  2. By initializing a dictionary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write the Python code to create an employee’s data frame from the “emp.csv” file and display the head and summary.

A
  1. .read_csv()
  2. .head() function
  3. .describe method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How will you select the Department and Age columns from an Employee data frame?

A

df[[‘Department’, ‘Age’]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Suppose there is an array, extract the value 8 using 2D indexing.

num = np.array([[1,2,3],[4,5,6],[7,8,9]]).

A

num[2, 1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Suppose there is an array that has values [0,1,2,3,4,5,6,7,8,9]. How will you display the following values from the array - [1,3,5,7,9]?

A

Since we only want the odd number from 0 to 9, you can perform the modulus operation and check if the remainder is equal to 1.

arr[arr % 2 == 1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

There are two arrays, ‘a’ and ‘b’. Stack the arrays a and b horizontally using the NumPy library in Python.

A

You can either use the concatenate() or the hstack() function to stack the arrays.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you add a column to a Pandas Data Frame?

A

Declare a list of values that will be converted into a column, and then:
df[‘name_of_the_column’] = list_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly