I have a df
containing some references for my projects, such like this:
root_path Credentials
Project1 path/to/ cred1.json
Project2 path/to/ cred2.json
Project3 path/to/ cred3.json
I need a third column Client
to save the response of the connection to BigQuery API, which is an object. The argument to pass to the function is the string formed by df['root_path'] + df['Credentials']
. For this, I tried with this two queries:
Using
apply()
df['Client'] = df.apply(lambda x : bigquery.Client.from_service_account_json((df['root_path'] + df['Credentials']).values), axis = 1)
Using
map()
df['Client'] = map(lambda root,bq : bigquery.Client.from_service_account_json(root + bq), df['root_path'], df['Credentials'])
Finally, the second query gave me the result I wanted. Could someone explain me why the second works and the first not? As far as I understand, it's because the first query returns everytime the whole series of objects, and the second calls the function row by row.
Thanks in advance.