Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Merge pandas dataframes and transform in SQL

I have few dataframes:

DF_1

|    | TYPE | SYMBOL | DESCRIPTION | OPOL | FIRST_INTEREST_DATE |
|----|------|--------|-------------|------|---------------------|
|  0 | BOND |      1 | FIRST       |   10 |            20220531 |
|  1 | BOND |      2 | SECOND      |   20 |            20220515 |
|  2 | BOND |      3 | THIRD       |   30 |            20220630 |
|  3 | BOND |      4 | FOURTH      |   40 |            20210815 |

DF_2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

|    | TYPE  | SYMBOL | DESCRIPTION | OPOL | ISIN         |
|----|-------|--------|-------------|------|--------------|
|  0 | STOCK |      1 | FIRST       |  101 | ABCDEFGHIKLM |
|  1 | STOCK |      7 | SEVENTH     |  202 | MLKIHGFEDCBA |
|  2 | STOCK |      9 | NINETH      |  303 | OPQRSTUVWXYZ |
|  3 | STOCK |     13 | THIRTEENTH  |  404 | ZYXWVUTSRQPO |
|  4 | STOCK |     17 | SEVENTEENTH |  505 | ABCDEFFEDCBA |

How can i get dataframe DF_3 like table in bottom? And is it possible to transorm DF_3 in sql format?

|    | TYPE  | SYMBOL | DESCRIPTION   |   OPOL |FIRST_INTEREST_DATE| ISIN         |
|----|-------|--------|---------------|--------|-------------------|--------------|
|  0 | BOND  |      1 | FIRST         |     10 |          20220531 |              |
|  1 | BOND  |      2 | SECOND        |     20 |          20220515 |              |
|  2 | BOND  |      3 | THIRD         |     30 |          20220630 |              |
|  3 | BOND  |      4 | FOURTH        |     40 |          20210815 |              |
|  4 | STOCK |      1 | FIRST         |    101 |                   | ABCDEFGHIKLM |
|  5 | STOCK |      7 | SEVENTH       |    202 |                   | MLKIHGFEDCBA |
|  6 | STOCK |      9 | NINETH        |    303 |                   | OPQRSTUVWXYZ |
|  7 | STOCK |     13 | THIRTEENTH    |    404 |                   | ZYXWVUTSRQPO |
|  8 | STOCK |     17 | SEVENTEENTH   |    505 |                   | ABCDEFFEDCBA |

>Solution :

you need to upload code or show a sample of your data.

Anyways here’s a solution based on a limited information that you’ve provided:

df_3 = pd.concat([df_1, df_2], axis=0)

then you can use

from sqlalchemy import create_engine
engine = create_engine('sqlite://', echo=False)
df_3.to_sql('your_df_name', con=engine)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading