import pandas as pd
df = pd.DataFrame([[1,'192.168.1.10', '45.7.12.34', 'abc'],[4, '10.10.1.11', '90.90.67.33', 'def'], [77, '52.1.7.90', '67.5.3.5', 'ghi' ], [90, '19.19.90.7', '77.88.99.44', 'xyz']], columns=['A', 'sip', 'dip', 'location'])
addrs = {'192.168.1.10': 'myhost.net', '45.7.12.34': 'myhost-goo.net', '10.10.1.11': 'myhost-foo.net' }`enter code here`
df[['sip','dip']].replace(addrs, inplace=True)
This code returns the warning, and in fact it does not replace dataframe
's cell values:
/usr/lib/python3.5/site-packages/pandas/core/frame.py:4042: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy method=method)
Python-3.5.2, pandas-0.24.2
Is it not possible to replace values in multiple columns with dictionary values on one call?