World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
How to import data from Excel in pandas as a list?
To import data from Excel in pandas as a list, you can follow these steps:
Here's an example code to illustrate the process:
import pandas as pd # Load the Excel file data = pd.read_excel('data.xlsx', sheet_name='Sheet1') # Convert data to a list data_list = data.values.tolist() print(data_list)
In the above code, we first import the pandas library and then load the Excel file using the read_excel() function. We specify the sheet name as 'Sheet1' to select the required sheet from the Excel file.
Next, we convert the loaded data to a list using the values attribute of the pandas dataframe and the tolist() function.
Finally, we print the data_list to verify if the data has been loaded as a list.
Running random forest algorithm with one variable