Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Created February 9, 2020 20:17
Show Gist options
  • Save rchardptrsn/ffa7b6223e196d90ccf86efd8e48daa8 to your computer and use it in GitHub Desktop.
Save rchardptrsn/ffa7b6223e196d90ccf86efd8e48daa8 to your computer and use it in GitHub Desktop.
# https://docs.microsoft.com/en-us/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python#upsertitem-database-or-container-link--document--options-none-
# Write rows of a pandas DataFrame as items to the Database Container
# Create Connection Link string
collection_link = database_link + '/colls/' + 'HDIcontainer'
# Write rows of a pandas DataFrame as items to the Database Container
for i in range(0,df.shape[0]):
# create a dictionary for the selected row
data_dict = dict(df.iloc[i,:])
# convert the dictionary to a json object.
data_dict = json.dumps(data_dict)
insert_data = client.UpsertItem(collection_link,json.loads(data_dict)
)
print('Records inserted successfully.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment