0

I'm facing issues uploading panda dfs with sqlalchemy. The issues arises when I try to write dfs with columns having list like features as depicted below:

enter image description here

The data that I write is based on JSON API data being converted to dataframes using pd.DataFrame.

The uploading is done using pandas.to_sql.

I can easily write the data if I omit the data with the list/array type feature. Any suggestions?

  • [`explode`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html) the list and then store the df in in SQL – anky Dec 02 '19 at 14:26
  • Hmm. Good suggestion. However, I get an AttributeError: "DataFrame" has no attribute to 'explode'. – random_user_567 Dec 02 '19 at 14:31
  • `explode` works only for pandas version `0.25` and above. For versions lower than this, you have to write a few lines on code. [here](https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe/53218939#53218939) are some ways to do it. I would update pandas but whatever suits you better :) – anky Dec 02 '19 at 14:33
  • It's not really what I'm looking for. Ideally I would want to write the data exactly as is. Thus, I would want SQL to accept the depicted format above or manipulate the format such that SQL will accept it. – random_user_567 Dec 03 '19 at 07:59

0 Answers0