pandas create column (assign value from other row)
Define a dictionary containing the data : data = {"id":[1,2], "parentid":[2,2], "version":[1.1,2.1], }
Convert the dictionary into DataFrame:df = pd.DataFrame(data)
Declare a list that is to be converted into a column: parentVersion= [2.1, 2.1]
Using 'parentVersion' as the column name: df['parentVersion'] = parentVersion
Observe the result: print(df)
I have dataframe with 3 columns (id, parentId, version) and I need to add new column parentVersion (version from parentid) :




id
parentid
version
parentVersion




1
2
1.1
2.1


2
2
2.1
2.1