I have trouble in getting values from a Json and storing in a Dataframe.
My Json looks like
{
"issues": [
{
"expand": "operations",
"id": "1",
"fields": {
"customfield_100": [
{
"self": "https://url1001",
"value": "Mobile",
"id": "1001",
"disabled": "false"
}
]
}
},
{
"expand": "operations",
"id": "2",
"fields": {
"customfield_100": [
{
"self": "https://url1002",
"value": "Desktop",
"id": "1002",
"disabled": false
},
{
"self": "https://url1001",
"value": "Mobile",
"id": "1001",
"disabled": false
}
]
}
},
{
"expand": "operations",
"id": "3",
"fields": {
"customfield_100": [
{
"self": "https://url1003",
"value": "ios",
"id": "1002",
"disabled": false
}
]
}
},
{
"expand": "operations",
"id": "4",
"fields": {
"customfield_100": [
{
"self": "https://url1002",
"value": "Desktop",
"id": "1002",
"disabled": false
},
{
"self": "https://url1001",
"value": "Mobile",
"id": "1001",
"disabled": false
},
{
"self": "https://url1003",
"value": "ios",
"id": "1003",
"disabled": false
}
]
}
}
]
}
Below is my part of the code
df2=pd.dataframe()
d=pd.json_normalize(json.loads(df1['customfield_100'].to_json(orient='record')))
filtered_component=[]
for index in range(len(issues.id)):
if((pd.json_normalize(df1['customfield_100'][index])).size>0):
filtered_component.append(d[0][index]['value']
else:
filtered_component.append('No Component')
df2['Component']=filterd_component
When i list df2[‘Component’], i am getting the below output
'Mobile'
'Desktop'
'ios'
'Desktop'
I would like my output to be like(when i list df2[components]) i.e if more than single value for customfield_100 then i would like those to be separated by ;. I am not sure how the loop/code should be written for it
'Mobile'
'Desktop';'Mobile'
'ios'
'Desktop';'Mobile';'ios'
2
Answers
If
data
contains your parsed Json data then you can do:This prints:
Then you can group by
main_id
, e.g.:This prints:
Another possible solution:
where
Output: