LoginSignup
0
1

More than 3 years have passed since last update.

pandas.IntervalをStringにキャストする方法

Posted at

pd.cutしたDataFrameをto_sqlするときに以下のエラーが起きて悩んだのでメモ

sqlite3.InterfaceError: Error binding parameter 3 - probably unsupported type.

👇astype(object)はエラー🤮

df['interval'] = pd.cut(df['x'], 3)
df['interval'] = df['interval'].astype(object)
df['interval'] = df['interval'].str.replace(', ', '~')
TypeError: Object of type 'Interval' is not JSON serializable

👇astype(str)はいける🙆‍♂️

df['interval'] = pd.cut(df['x'], 3)
df['interval'] = df['interval'].astype(str)
df['interval'] = df['interval'].str.replace(', ', '~')

無事書き出せました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1