Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Upper function

import pandas as pd
df = pd.DataFrame([{"email": "test@gmail.com"}])
is_upper = lambda x: x.upper() if isinstance(x, str) else x
df = df.applymap(trim_strings)
a = df.to_dict("records")

The response I get :

[{'email': 'test@gmail.com'}]

The response I expected :

[{'email': 'TEST@GMAIL.COM'}]

What can be the issue here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To get the expected output, consider try this:

df['email'] = df['email'].str.upper()

Your df:

    email
0   TEST@GMAIL.COM

to get the dictionary:

foo_dict = df.to_dict()
foo_dict 
{'email': {0: 'TEST@GMAIL.COM'}}

Block Code:

import pandas as pd
df = pd.DataFrame([{"email": "test@gmail.com"}])
df['email'] = df['email'].str.upper()
foo_dict = df.to_dict()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading