0

I want to store a value of a dataframe and use it to send an email:

def config():
    sql_con_obj = SqlConnector()
    sql_con_obj.connect()
    sql_con_obj.con.commit()
    sql = "SELECT * FROM bd_opensgc.Config"
    df = pandas.read_sql_query(sql, sql_con_obj.con)
    df.to_csv("Config.csv", index=False, encoding="utf-8")
    Emails = df['Email']
    sql_con_obj.disconnect()
    del sql_con_obj
    return Emails

df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1 entries, 0 to 0
Data columns (total 1 columns):
 #   Column           Non-Null Count  Dtype
---  ------           --------------  -----
 1   Email            1 non-null      object
dtypes: object(1)

in the email function i get the Emails variable and say that

Emails=config()
you = Emails
msg['To'] =you
smtp.sendmail(me,you, msg.as_string())

and it gives me this error :

'Series' object has no attribute 'encode'
Ricardoke
  • 133
  • 1
  • 3
  • 10

1 Answers1

2

You should use .values or iloc, otherwise you'd get the entire column that is always of type Series

For Example:

Emails = df['Email'].values[0]

Check this out:

How to get a value from a cell of a dataframe?

jvrn3
  • 600
  • 1
  • 5
  • 18