This should be simple, but for some reason I am not understanding where I am going wrong.
I have a sample dataframe:
df = pd.DataFrame({'name':('Nick', 'Nick', 'Nick', 'David'), 'num':(1, 2, 3, 4)})
I want to create a new column called link where if the value in name is 'Nick', then the link value would be some text + the num column value.
This is the code I am currently using:
df['link'] = np.where(df.name == "Nick","https://" + str(df.num), '')
But instead of the first row being:
0, Nick, 1, "https://1"
It is:
0, Nick, 1, "https://0 1\n1 2\n2 3\n3 4\nName: num, dtype: int64"
Which means it is using the whole num column, rather the row.
Any idea what I am doing wrong? And on a side note, I have to do this for millions of rows, any suggestions of the most efficient way of doing it?
