-2

I am trying to append 3 tables. However, I hope there will be no duplicated items after appended. Preserve value In order: Table 1 -> Table 2 -> Table 3 Is it possible to conduct it in Python using Pandas or Numpy? Great thanks.

import pandas as pd
Table1 = pd.DataFrame([[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1]], columns=['Item', 'Value'])
Table2 = pd.DataFrame([[5, 2], [6, 2], [7, 2], [8, 2]], columns=['Item', 'Value'])
Table3 = pd.DataFrame([[8, 3], [9, 3], [10, 3]], columns=['Item', 'Value'])
Append = pd.DataFrame([[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 2], [8, 2], [9, 3], [10, 3]], columns=['Item', 'Value'])

enter image description here enter image description here enter image description here

enter image description here

Ng Ct
  • 51
  • 7
  • It would be good to provide the input data as text that I can copy and paste. The answer is very simple but I won't type all those values in by hand. – timgeb Jun 24 '20 at 07:43
  • See also [how to make good reproducible pandas examples](https://stackoverflow.com/a/20159305/3620003). – timgeb Jun 24 '20 at 07:43
  • 1
    @timgeb Thanks for your suggestions. Appreciated if any help for that – Ng Ct Jun 24 '20 at 07:59
  • Voted to reopen because OP supplied sample data. – timgeb Jun 24 '20 at 09:40

1 Answers1

0

You can consider using append function in pandas dataframe:

# add tables verically
Append = Table1.append([Table2,Table3])
# drop duplicated rows + reset index
Append = Append.drop_duplicates().reset_index(drop=True)
RunTheGauntlet
  • 392
  • 1
  • 4
  • 15