The to_xarray
method is used to convert the given DataFrame to a xarray
object.
Note: Refer xarray to learn more about
xarray
data structure.
Note: Click here to learn more about the pandas library.
DataFrame.to_xarray()
The method has no parameters.
Let’s look at the code below:
import pandas as pd df = pd.DataFrame({'Name':['Dom', 'Celeste', 'Abhi', 'Gaby', 'Rachel', 'Sam'],'Age': [20,25,30,18,25,20]}) xarr = df.to_xarray() print("The xarray representation of the df is \n", xarr)
Line 3: We create a custom DataFrame called df
.
Line 5: We invoke the to_xarray()
on df
to get the xarray
representation of the DataFrame.
RELATED TAGS
CONTRIBUTOR
View all Courses