-2

I run two queries in python (that would generate two different data sets but has the same title). I combined them into one data set using python and it looks something like this: (however this actual data set is not showing anywhere, I just use table_a + table_b and combined them into one)

date      symbol    data
10/9/2018   a       0.1
10/9/2018   b       0.2
10/9/2018   c       0.3
10/9/2018   a       0.1
10/9/2018   a       0.1

If i want to remove the duplicates symbol and produce output like:

date      symbol    data
10/9/2018   a       0.1
10/9/2018   b       0.2
10/9/2018   c       0.3

how should I do it?

Thanks!

user10382480
  • 23
  • 1
  • 5
  • 2
    Hint: `select distinct`. – Gordon Linoff Oct 11 '18 at 17:10
  • Welcome to SO. You could have found this with a search for 'SQL remove duplicates' http://idownvotedbecau.se/noresearch/ – dfundako Oct 11 '18 at 17:14
  • Are you using pandas dataframe?as you mentioned table,tagged sql but want to remove using python. It is confusing – mad_ Oct 11 '18 at 17:26
  • Possible duplicate of [Select first row in each GROUP BY group?](https://stackoverflow.com/questions/3800551/select-first-row-in-each-group-by-group) – mad_ Oct 11 '18 at 17:28

1 Answers1

0

Just use DISTINCT to remove duplicate rows. You don't post your SQL but it should look like:

select distinct date, symbol, data from my_table

Please note that DISTINCT applies to the full row, not the first column only.

The Impaler
  • 45,731
  • 9
  • 39
  • 76
  • Hi, the dates are the same though, but I only want to select distinct symbol (does not matter if they have the same date). How can the distinct function tell that which one I am selecting from? – user10382480 Oct 11 '18 at 17:21
  • and by the way I want to remove the duplicates through python, not sql. – user10382480 Oct 11 '18 at 17:24