0

I have the following dataframe

[![enter image description here][1]][1]

I want to remove the duplicates in ID column and keep all the values corresponding to other columns in one row as shown below

[![enter image description here][2]][2]

I used iterrows but didn't get the required result. Please help me with python code. [1]: https://i.stack.imgur.com/1J22k.png [2]: https://i.stack.imgur.com/kZKYc.png

  • The link to your images were not inserted properly – gtomer Oct 06 '20 at 14:47
  • Always provide a [mre], with **code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting), [Not Screenshots](https://meta.stackoverflow.com/questions/303812/)**. It is likely the question will be down-voted and closed. You are discouraging assistance because no one wants to retype your data or code, and screenshots are often illegible. [edit] the question and **add text**. Please see [How to provide a reproducible copy of your DataFrame using `df.head(30).to_clipboard(sep=',')`](https://stackoverflow.com/questions/52413246). – Trenton McKinney Oct 06 '20 at 14:50
  • Does this answer your question? [Drop all duplicate rows across multiple columns in Python Pandas](https://stackoverflow.com/questions/23667369/drop-all-duplicate-rows-across-multiple-columns-in-python-pandas) – Trenton McKinney Oct 06 '20 at 14:54
  • Does this answer your question? [How do I get a list of all the duplicate items using pandas in python?](https://stackoverflow.com/questions/14657241/) – Trenton McKinney Oct 06 '20 at 14:56

1 Answers1

0

Try this:

df.apply(lambda x: pd.Series(x.dropna().to_numpy()))

Output:

   1st Month Sales  2nd Month Sales  3rd Month Sales
0           2500.0           3450.0           1349.0
1              NaN           1200.0           2300.0
Scott Boston
  • 147,308
  • 15
  • 139
  • 187