-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NaN value in dataframe caused _write_mysql error #4199
Comments
closing as duplicate of #2754. Think current workaround is to first use |
I tried this, and got an error: df = DataFrame({'a': [1, 2, 3], 'b': ['1', '2', '3'], 'c': [nan, 2.0, 3.0]})
df[pd.isnull(df)] = None
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/duozhang/python-workspace/notebook/l-demo/<ipython-input-182-db74023de5e1> in <module>()
----> 1 df[pd.isnull(df)] = None
/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __setitem__(self, key, value)
2033 self._setitem_array(key, value)
2034 elif isinstance(key, DataFrame):
-> 2035 self._setitem_frame(key, value)
2036 else:
2037 # set column
/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _setitem_frame(self, key, value)
2068 if self._is_mixed_type:
2069 if not self._is_numeric_mixed_type:
-> 2070 raise ValueError('Cannot do boolean setting on mixed-type frame')
2071
2072 self.where(-key, value, inplace=True)
ValueError: Cannot do boolean setting on mixed-type frame And I found the solution in #1972 . In [10]: df.where(pd.notnull(df), None)
Out[10]:
a m p x
0 1 None 0 None
1 2 10 None None
2 3 11 20 None
3 4 12 21 None This code works good. |
You're right, this should "just work" from read_sql, and I think it'll be fixed in 0.13 (probably in dev quite soon). Team are currently working on better sql support, see #4163. Thanks for reporting this and if you find any other bugs please let us know! |
Hi, Although this tissue is closed, I'm still getting the error:OperationalError: (1054, "Unknown column 'nan' in 'field list'"). The following does not work: my pandas version is higher than 0.13: '0.22.0' my other versions: |
The text was updated successfully, but these errors were encountered: