0

I read data from mssql and as in data format below:

 from pandas import DataFrame
 import pandas as pd

  data = pd.DataFrame({'Index':[1,2],'Metrics':[" 
  ['ga:users','ga:newUsers']","['ga:bounceRate','ga:pageviews']"]})
  

What I need is list of each row dimension column:

 list1= ['ga:users','ga:newUsers']
 list2=['ga:bounceRate','ga:pageviews']

below what I tried but :

  Metrics1=data.loc[data['Index']==1,'Metrics'].iloc[0][1:-1].split(', ')

I got some extra "

  ["'ga:users','ga:newUsers'"] 

How can I fix this please help? Thank you

melik
  • 1,268
  • 3
  • 21
  • 42
  • 1
    You have the `"`s in your original definition of `data`. Are you looking for an automated way of removing them? If you can trust the source, you can use `eval()`, but that is not safe in general. – Jacob Stuligross Aug 16 '23 at 13:12
  • `ast.literal_eval` is the safer way – mozway Aug 16 '23 at 13:16

0 Answers0