python - Merge rows in dataframe -
part of csv-file ('data.csv') have process, looks this:
parent_id,parent_name,type,companyname,custsupid,streetaddress 3,customer,,,c0010, 3,customer,a,,, 3,customer,,ace systems,, 3,customer,,,,straat 10 7,customer,,,q8484, 7,customer,b,,, 7,customer,,xyz automat,, 7,customer,,,,laan 99
to import file dataframe do:
df = pd.read_csv('data.csv').fillna('')
this results in:
------------------------------------------------------------------ | |parent_id|parent_name|type|companyname|custsupid|streetaddress| ------------------------------------------------------------------ |0|3 |customer | | |c0010 | | |1|3 |customer |a | | | | |2|3 |customer | |ace systems| | | |3|3 |customer | | | |straat 10 | |4|7 |customer | | |q8484 | | |5|7 |customer |b | | | | |6|7 |customer | |xyz automat| | | |7|7 |customer | | | |laan 99 | ------------------------------------------------------------------
however, want end with, dataframe looks this:
------------------------------------------------------------------ | |parent_id|parent_name|type|companyname|custsupid|streetaddress| ------------------------------------------------------------------ |0|3 |customer |a |ace systems|c0010 |straat 10 | |1|7 |customer |b |xyz automat|q8484 |laan 99 | ------------------------------------------------------------------
i tried df.groupby etc. can't produce desired result.
is there way accomplish pandas dataframe?
in [37]: df.groupby(['parent_id', 'parent_name']).sum() out[37]: type companyname custsupid streetaddress parent_id parent_name 3 customer ace systems c0010 straat 10 7 customer b xyz automat q8484 laan 99
sum
adding strings together, , relies on fact adding empty strings non-empty string returns non-empty string.
Comments
Post a Comment