Error reading a column of a file . xlsx using Python pandas library

Asked

Viewed 569 times

0

I need to create a Python list from a column of an Excel file using the pandas library. I have already installed all library components and the files are in the same directory.

from pandas import DataFrame
import pandas as pd

filename = r'email.xlsx'
df = pd.read_excel(filename)

email = list[df['EMAIL']]

print(email)

While running this file, an error is charged on line 7 of the program:

Traceback (Most recent call last): File "main.py", line 7, in email = list[df['EMAIL']] Typeerror: 'type' Object is not subscriptable

I’ve been through the library documentation, but I can’t seem to figure it out. Thank you! D

1 answer

1

I believe that this should work

import pandas as pd

from pandas import DataFrame

df = pd.read_excel('email.xlsx', sheet_name='Planilha1')

email = df['EMAIL'].values.tolist()

print(email)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.