I’m trying to read some comma separated values[string values] from a particular column in excel. I want to store these values as they are in a list in python.
This is the data in that column : ‘a’,’b c’,’d’,’f,g’
When i try reading the same from excel to python, it is read as a string :
This is what it looks like : "’a’,’b c’,’d’,’f,g’" giving me a complete string.
I cannot split it based on ‘,’ since my data can have ‘,’ within it.
I just want [‘a’,’b c’,’d’,’f,g’], how do i get this ?
>Solution :
IIUC, you can try this :
df = pd.read_excel("file.xlsx")
df["col"] = df["col"].str.strip("'").str.split("','")
Output :
print(df.iloc[0,0])
#['a', 'b c', 'd', 'f,g']
print(df)
col
0 [a, b c, d, f,g]
Input used :
