The following code transforms the table like this:
col1 col2
0 1 3.0
1 2 4.0
2 C345 NaN
3 A56665 4.0
4 34553 NaN
5 353535 4.0
col1 col2
0 1 3
1 2 4
2 C345 C345
3 A56665 4
4 34553 34553
5 353535 4
.
import pandas as pd
d = {'col1': [1, 2, "C345", "A56665", 34553, 353535], 'col2': [3, 4,None, 4,None, 4]}
df = pd.DataFrame(data=d)
df.col1.astype(str)
print(df)
df.col2.fillna(df.col1, inplace=True)
print(df)
However, I get a SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
when apllying this approach on large data sets. What am I doing wrong/ not in the intended way?