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

remove [] from output values in a dataframe

I’m pulling data from google trends and the output values come out as follows:

                 date value
0 2017-01-01 03:00:00  [65]
1 2017-01-01 03:01:00  [66]
2 2017-01-01 03:02:00  [77]
3 2017-01-01 03:03:00  [64]
4 2017-01-01 03:04:00  [94]

I’ve trimmed what I don’t need. My issue is I need to remove the brackets and make the calue column an int. I’ve tried the following:

result['value'].apply(lambda x: pd.Series(str(x).replace('[', '').replace(']', '')))

But I get the same output either way. Any thoughts or suggestions?

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 :

You can also do:

df['value'] = df['value'].explode()

Output:

                  date value
0 2017-01-01  03:00:00    65
1 2017-01-01  03:01:00    66
2 2017-01-01  03:02:00    77
3 2017-01-01  03:03:00    64
4 2017-01-01  03:04:00    94
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