Q: Failing while passing dataframe column seperated by comma into a API I have to pass  locations to API to retrieve values.
Working Code
 dfs = []
locations = ['ZRH','SIN']
for loc in locations:
    response = requests.get(f'https://risk.dev.tyche.eu-central-1.aws.int.kn/il/risk/location/{loc}', headers=headers, verify=False)
    if 'items' in data:
        df = pd.json_normalize(data, 'items', 'totalItems')     
        df1 = pd.concat([pd.DataFrame(x) for x in df.pop('relatedEntities')], keys=df.index).add_prefix('relatedEntities.')
        df3 = df.join((df1).reset_index(level=1, drop=True))
        dfs.append(df3)

df = pd.concat(dfs, ignore_index=True)

Failing Code ( while passing as parameter)
When I try to pass location as parameter which is created another dataframe column it fails.
Unique_Location = data['LOCATION'].unique()
Unique_Location = pd.DataFrame( list(zip(Unique_Location)), columns =['Unique_Location'])
t= ','.join(map(repr,Unique_Location['Unique_Location'] ))

locations = [t]
    for loc in locations:
        response = requests.get(f'https://risk.dev.logindex.com/il/risk/location/{loc}', headers=headers)
        data = json.loads(response.text)
        df = pd.json_normalize(data, 'items', 'totalItems') 

What is  wrong in my code?
Error
`c:\users\ashok.eapen\pycharmprojects\rs-components\venv\lib\site-packages\pandas\io\json\_normalize.py in _pull_records(js, spec)
    246         if has non iterable value.
    247         """
--> 248         result = _pull_field(js, spec)
    249 
    250         # GH 31507 GH 30145, GH 26284 if result is not list, raise TypeError if not

c:\users\ashok.eapen\pycharmprojects\rs-components\venv\lib\site-packages\pandas\io\json\_normalize.py in _pull_field(js, spec)
    237                 result = result[field]
    238         else:
--> 239             result = result[spec]
    240         return result
    241 

KeyError: 'items'

`

A: You can test if items exist in json like:
dfs = []
locations = ['NZAKL', 'NZ23-USBCH', 'DEBAD', 'ARBUE', 'AR02_GSTI', 'AEJEA', 'UYMVD', 'UY03', 'AE01_GSTI', 'TH02_GSTI', 'JO01_GSTI', 'ITSIM', 'GB75_GSTI', 'DEAMA', 'DE273_GSTI', 'ITPRO', 'AT07_GSTI', 'FR05', 'FRHAU', 'FR01_GSTI', 'FRHER', 'ES70X-FRLBM', 'THNEO']
for loc in locations:
    response = requests.get(f'https://risk.dev.logindex.com/il/risk/location/{loc}', headers=headers)
    data = json.loads(response.text)
    if 'items' in data:
        if len(data['items']) > 0:
            df = pd.json_normalize(data, 'items', 'totalItems') 
            
            #NaN in column, so failed - replace NaN to empty list
            f = lambda x: x if isinstance(x, list) else []
            df['raw.identifiers'] = df['raw.identifiers'].apply(f)
            df['raw.relationships'] = df['raw.relationships'].apply(f)
            df1 = pd.concat([pd.DataFrame(x) for x in df.pop('raw.identifiers')], keys=df.index).add_prefix('raw.identifiers.')
            df2 = pd.concat([pd.DataFrame(x) for x in df.pop('raw.relationships')], keys=df.index).add_prefix('raw.relationships.')
            
            df3 = df.join(df1.join(df2).reset_index(level=1, drop=True))
            dfs.append(df3)

df = pd.concat(dfs, ignore_index=True)

