1

I have two CSV files:

Each of them has three columns: time, X and Y. I want to retain the rows of both files which has same time(intersection of column 0) and delete the rows with different time.

For example:

a.csv

time                      x          y

2018/01/01/01:00:45:03    3          4

2018/01/01/01:00:45:05    4.5        5

2018/01/01/01:00:45:06    5         5.5

2018/01/01/01:00:45:08    5.5       6.5

b.csv

time                     x   y

2018/01/01/01:00:45:01  3.5 4.5

2018/01/01/01:00:45:05  5.5 5.5

2018/01/01/01:00:45:06  8   6.5

2018/01/01/01:00:45:09  10  9

**expected output **c.csv****

time                    x   y

2018/01/01/01:00:45:05  5.5 5.5

2018/01/01/01:00:45:06  8   6.5

Thanks in advance!

Ankur Sinha
  • 6,473
  • 7
  • 42
  • 73

1 Answers1

0

You can use a simple loc statement with .isin():

c_csv = b_csv.loc[b_csv['time'].isin(a_csv['time'])]
sacuL
  • 49,704
  • 8
  • 81
  • 106