I have a csv that has values in a column like this
When I read it in a df and print it, it looks like this:
I understand that it is unable to pretty print it but when I try to extract value of x y width and height then on height it gives list index out of range
import pandas as pd
df = pd.read_csv("./data/SSCARDTemplate.csv")
for i in df["region_id"]:
coor = df.loc[df["region_id"] == i, "region_shape_attributes"]
dic = coor.to_string().split(",")
print(coor.to_string())
x = dic[1].split(":")[1]
y = dic[2].split(":")[1]
w = dic[3].split(":")[1]
print(dic[4])
h = dic[4].split(":")[1]
break
This is reproducible pandas example
{'#filename': {0: 'SSCARDTemplate.jpg',
1: 'SSCARDTemplate.jpg',
2: 'SSCARDTemplate.jpg',
3: 'SSCARDTemplate.jpg',
4: 'SSCARDTemplate.jpg',
5: 'SSCARDTemplate.jpg'},
'file_size': {0: 110231,
1: 110231,
2: 110231,
3: 110231,
4: 110231,
5: 110231},
'file_attributes': {0: '{}', 1: '{}', 2: '{}', 3: '{}', 4: '{}', 5: '{}'},
'region_count': {0: 6, 1: 6, 2: 6, 3: 6, 4: 6, 5: 6},
'region_id': {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5},
'region_shape_attributes': {0: '{"name":"rect","x":402,"y":640,"width":521,"height":93}',
1: '{"name":"rect","x":399,"y":723,"width":523,"height":88}',
2: '{"name":"rect","x":402,"y":803,"width":526,"height":98}',
3: '{"name":"rect","x":399,"y":889,"width":531,"height":101}',
4: '{"name":"rect","x":404,"y":982,"width":526,"height":91}',
5: '{"name":"rect","x":402,"y":1062,"width":529,"height":96}'},
'region_attributes': {0: '{}', 1: '{}', 2: '{}', 3: '{}', 4: '{}', 5: '{}'}}
question from:
https://stackoverflow.com/questions/65933348/unable-to-extract-the-entire-value-of-pandas-cell