Last active
September 4, 2022 22:24
-
-
Save rbtrsv/fe5c6bfed5dc196b7e80fe243baadc42 to your computer and use it in GitHub Desktop.
Export Pandas dataframe to Firestore collection
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
| import pandas as pd | |
| # The is an alternative | |
| # from google.cloud import firestore | |
| # db = firestore.Client() | |
| # db = firestore.Client.from_service_account_json("/Users/your.name/yada-yada-firebase-adminsdk.json") | |
| import firebase_admin | |
| from firebase_admin import credentials | |
| from firebase_admin import firestore | |
| cred = credentials.Certificate('/Users/your.name/yada-yada-firebase-adminsdk.json') | |
| app = firebase_admin.initialize_app(cred) | |
| db = firestore.client() | |
| df = pd.DataFrame() | |
| for indices, row in df.iterrows(): | |
| doc_ref = db.collection("stocks").document(row['Symbol']) | |
| doc_ref.set({ | |
| "Symbol": row['Symbol'], | |
| "Name": row['Name'], | |
| "Sector": row['Sector'] | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment