All Courses

How to import data from Excel in pandas as a list?

By Sde221876@gmail.com, a month ago
  • Bookmark
0

How to import data from Excel in pandas as a list?

Pandas
Import data from excel
Import data
List
1 Answer
0
Goutamp777

To import data from Excel in pandas as a list, you can follow these steps:

  1. Install the pandas library using the pip or conda command in the terminal.
  2. Import the pandas library and load the Excel file using the read_excel() function.
  3. Select the sheet from the Excel file and convert the data to a list using the tolist() function.

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.


Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More