SettingWithCopyWarningメモ

こんな感じでdataframeにseriesを入れようとするとエラーが出る

df2['time'] = s1

表示されるエラー文はこんな感じ

/Users/Suzuki_Yasuharu/miniconda3/lib/python3.6/site-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  This is separate from the ipykernel package so we can avoid doing imports until

対策

# こう↓するとエラーが出なくなる
pd.options.mode.chained_assignment = None
df2['time'] = s1

消費メモリを小さくするためのワーニングですんで、そのこと理解した上で使いましょー(・ω・)ノシ


参考サイト
indexing-view-versus-copy(エラー文に書いてあるページ)
pandas 0.21.0 documentation
How to deal with SettingWithCopyWarning in Pandas?


ちなみにこちら↓のようにconcatするとワーニング出ません(なんかちょっとやりたいことがが変わってしまう気はしますが)
python pandasでの列(column)へのSeriesの追加


要素1つ1つを選択しているのならこちらのやり方が正です。
Pythonの覚え書き(DataFrameのSettingWithCopyWarningの対処方法)