Reputation: 1185
I read lot of posts and information about that error in pandas. I try to write a code in different way, but nothing helps and it's still unclear to me.
I have a dataframe - df1 with three cols:
SampleIdInt, Username, Signature
When I try to add a column filled '1' to df I got an SettingWithCopyWarning. Code:
df1['PolName'] = 1
In my another script that code didn't throw error, so why in this case i got it? I have just delared dataframe and dictionary.
Next, when I try to translate values by a dictionary it again throw a error. Code:
df1.loc[:,'PolName'] = df1['SampleIdInt'].apply(lambda y:slownik[y] if y in slownik.keys() else 'None')
I tried with loc, iloc, with different code syntax. Everytime I gor an error. What is weird? Somethimes I got an error and code modified a df anyway, sometimes I got an error, and df stay unchaged - I don't change anything in that code.
Can someone explain me what is a problem, exactly on above example?
Important parts of code. Could be useful:
baza = pd.read_csv('Zeszyt1.csv', sep = ';')
snps = pd.read_csv('snps.csv', header = None, low_memory = False, sep = ',')
vals = snps.loc[snps.duplicated(['SampleIdInt',5]), 'SampleIdInt'].unique()
mask = snps['SampleIdInt'].isin(vals)
df1 = snps[~mask]
Upvotes: 0
Views: 35