I would like to concat rows value in one row in a dataframe, given one column. Then I would like to receive an edited dataframe.
Input Data :
ID F_Name L_Name Address SSN Phone
123 Sam Doe 123 12345 111-111-1111
123 Sam Doe 123 12345 222-222-2222
123 Sam Doe abc345 12345 111-111-1111
123 Sam Doe abc345 12345 222-222-2222
456 Naveen Gupta 456 45678 333-333-3333
456 Manish Gupta 456 45678 333-333-3333
Expected Output Data :
myschema = {
"ID":"123"
"F_Name":"Sam"
"L_Name":"Doe"
"Addess":"[123, abc345]"
"Phone":"[111-111-1111,222-222-2222]"
"SSN":"12345"
}
{
"ID":"456"
"F_Name":"[Naveen, Manish]"
"L_Name":"Gupta"
"Addess":"456"
"Phone":"[333-333-333]"
"SSN":"45678"
}
Code Tried :
df = pd.read_csv('data.csv')
print(df)
pd.uniquedirectly:myschema = df.groupby('ID', as_index=False).agg(pd.unique).to_dict(orient='records')