Jellyland

关于SettingWithCopyWarning

在对DataFrame添加新列的时候时常会遇到SettingWithCopyWarning:

Google了一番,最后在stack overflow上找到了最恰当的用法。

import pandas as pd
pd._version.get_versions()

"""
{'dirty': False,
 'error': None,
 'full-revisionid': 'a00154dcfe5057cb3fd86653172e74b6893e337d',
 'version': '0.22.0'}
"""
df['new_column'] = ...
df.loc[:, 'new_column'] = ...
df = df.assign(new_column = ...)

#Python