合并两个数据集但不重复

时间:2019-05-01 08:48:48

标签: r merge tidyr

我想从一个数据框中附加信息,然后将其附加到另一个数据框,但是我只是无法使合并按照我想要的方式工作。

我的例子:

import datetime
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="",
  database='appointments'
)

eventDate = mydb.cursor()
eventDate.execute('SELECT event_date FROM appointdatetitle')
Date = eventDate.fetchall()

tdelta = datetime.timedelta(days=7)
today = datetime.date.today()
eday = Date
till_eday = eday - today
print(till_eday.days)
a <- data.frame(well = c(222, 222, 222, 21, 21,21,43,64,64,64),
                   area = c("H", "H", "H", "C", "C", "C", "D", "E", "E", "E"))

我希望结果看起来像这样:

b <- data.frame(well = c(222, 21, 43, 64),
                   score = c(12000, 10000, 9000, 20000))

但是我明白了(我不希望井号重复):

 well score area
1  222 12000 H
2   21 10000 C
3   43  9000 D
4   64 20000 E

我的实际数据包含数百行。

谢谢

2 个答案:

答案 0 :(得分:0)

由于在a中有重复项,因此也在merge中也有它们。一种选择是仅包含unique的{​​{1}}行,然后是a

merge

或者合并后使用merge(unique(a), b) # well area score #1 21 C 10000 #2 43 D 9000 #3 64 E 20000 #4 222 H 12000

unique

可以使用unique(merge(a, b)) dplyr的{​​{1}}来完成

left_join

答案 1 :(得分:0)

使用$.ajax ({ type: 'POST', url: "https:/www.bb.com?uId=123&mId=123", headers: { "Accept": "application/json", "Content-Type": "application/json", }, beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic dTHIgdfgsjdhgfsgfjhsfghsfkjs879"); }, dataType: 'json', success: function (data) { console.log(data); }, error: function (xhr, status, error) { console.log(xhr); console.log(status); console.log(error); } }); and for checking: $("input:checkbox[name=list]").click(function () { if ($(this).is(':checked')) { do that call } }); 加入

data.table