Python Flashcards
What is the correct syntax for reshape() function in NumPy?
reshape(array, shape)
What are the different ways to create a data frame in Pandas?
- By initializing a list
- By initializing a dictionary
Write the Python code to create an employee’s data frame from the “emp.csv” file and display the head and summary.
- .read_csv()
- .head() function
- .describe method
How will you select the Department and Age columns from an Employee data frame?
df[[‘Department’, ‘Age’]]
Suppose there is an array, extract the value 8 using 2D indexing.
num = np.array([[1,2,3],[4,5,6],[7,8,9]]).
num[2, 1]
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]?
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]
There are two arrays, ‘a’ and ‘b’. Stack the arrays a and b horizontally using the NumPy library in Python.
You can either use the concatenate() or the hstack() function to stack the arrays.
How can you add a column to a Pandas Data Frame?
Declare a list of values that will be converted into a column, and then:
df[‘name_of_the_column’] = list_name