Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

db_cleanup.py 509 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  1. '''
  2. Temporary until pandas gets some kind of upsert functionality
  3. '''
  4. from sqlalchemy import create_engine
  5. from lendingclub import config
  6. import pandas as pd
  7. # read, sort, drop
  8. disk_engine = create_engine(f'sqlite:///{config.lc_api_db}')
  9. df = pd.read_sql('lc_api_loans', disk_engine)
  10. df = df.sort_values(['id', 'funded_amount'])
  11. df = df.drop_duplicates('id', keep='last')
  12. # df = df.drop(['index', 'level_0'], axis=1)
  13. # write out
  14. df.to_sql('lc_api_loans', disk_engine, if_exists='replace', index=False)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...