Created
February 9, 2020 20:17
-
-
Save rchardptrsn/ffa7b6223e196d90ccf86efd8e48daa8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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