3

I have a dataframe as follows:

 Company LT MT ST 0 XYZ A - - 1 XYZ A - B 2 XYZ - C B 3 ABC R - - 4 ABC R - B 5 DEF A B - 6 DEF A B B 

what I want is to make a dataframe that can check whether company is duplicated or not and based on the duplication check for muliple columns LT, MT & ST. And if the values in these columns are repeatative than merge it onto single row entry for same company name. Output as follows:

 Company LT MT ST 0 XYZ A C B 1 ABC R - B 2 DEF A B B 

I have tried with df.drop_duplicates() but it doesn't solve my problem.

1 Answer 1

4

Use groupby and first with fillna

In [559]: (df.replace('-', np.nan) .groupby('Company', sort=False, as_index=False) .first() .fillna('-')) Out[559]: Company LT MT ST 0 XYZ A C B 1 ABC R - B 2 DEF A B B 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.