New to python. I have a dataframe in which I want to add a new column. This column should be filled with a string 0 or with a string based on a string coming from an other column (why? because the files I read sometimes have the hr data and sometimes not).
I can't seem to get this right. I always get a 0 also when I do have data for hr. I have looked into 'if then' examples (and other methods) but simply could not figure it out what I am doing wrong. Can someone please help me. First I define the column and set it to 0. Then I do an if condition to overwrite the 0 is the condition is satisfied (at least that is my intention). This I try to do with the if the string HR is somewhere in the df['veld'] column.
df['hr']='0'
if ("HR") in df['veld']:
df['hr']=df.veld.str.split('"HR":').str.get(1).str.split(',').str.get(0)
Aucun commentaire:
Enregistrer un commentaire