Quantcast
Channel: Removing duplicates from Pandas rows, replace them with NaNs, shift NaNs to end of rows - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by Henry Yik for Removing duplicates from Pandas rows, replace them...

Apply pd.Series.unique on each row, extract the result and re-contruct the dataframe:print (pd.DataFrame(df.apply(pd.Series.unique, axis=1).tolist())) 0 1 2 30 A B C D1 A D C None2 C B None None3 B A...

View Article



Answer by Andy L. for Removing duplicates from Pandas rows, replace them with...

Use apply and construct a new dataframe by pd.DataFrame.from_dict with option orient='index'df_final = pd.DataFrame.from_dict(df.apply(lambda x: x.drop_duplicates().tolist(), axis=1).to_dict(),...

View Article

Answer by BENY for Removing duplicates from Pandas rows, replace them with...

try something newdf = pd.DataFrame(list(map(pd.unique, df.values)))Out[447]: 0 1 2 30 A B C D1 A D C None2 C B None None3 B A None None

View Article

Answer by Sebastien D for Removing duplicates from Pandas rows, replace them...

You could search for duplicates on the row axis and then sort out the results to "push" the Nan at the end of the rows by sorting them out with a specific key:duplicates =...

View Article

Image may be NSFW.
Clik here to view.

Answer by ALollz for Removing duplicates from Pandas rows, replace them with...

You can stack and then drop_duplicates that way. Then we need to pivot with the help of a cumcount level. The stack preserves the order the values appear in along the rows and the cumcount ensures that...

View Article


Removing duplicates from Pandas rows, replace them with NaNs, shift NaNs to...

ProblemHow to remove duplicate cells from each row, considering each row separately (and perhaps replace them with NaNs) in a Pandas dataframe?It would be even better if we could shift all newly...

View Article
Browsing latest articles
Browse All 6 View Live


Latest Images