In python pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and the data. DataFrame can be created with the help of python dictionaries. Pandas also allow us to convert this DataFrame into a NumPy array using DataFrame.to_numpy() method.
pandas.DataFrame.to_numpy() Method
This method simply takes a DataFrame as a parameter and converts it into NumPy array. The data type of the returned array will be common of all the data types in the DataFrame which is passed as a parameter.
Syntax:
DataFrame.to_numpy(
dtype=None,
copy=False,
na_value=NoDefault.no_default
)
The dtype is the data type passed to the method, apart from dtype, it has two more optional parameters, i.e., copy and na_value.
To work with MultiIndex in Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Let us understand with the help of an example.
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer