I want to match certain parts of 2 dataframes by date and time and merge them into one of them. But my code is not working. I have 2 dataframe df and df2. First is df and second is df2. What can I do for this? I want to add Weather, Temp, Feels and after that to df.
here is the text verison of datafreames. It’s just a sample because they are too big
{'road': {0: 10500, 1: 10500, 2: 10500, 3: 105400, 4: 105400, 5: 106600, 6: 14100, 7: 22800, 8: 22800, 9: 22800}, 'date': {0: '2021.03.08 02:00:00', 1: '2021.03.08 05:45:00', 2: '2021.03.08 04:15:00', 3: '2021.03.07 21:30:00', 4: '2021.03.08 05:45:00', 5: '2021.03.08 05:45:00', 6: '2021.03.07 21:30:00', 7: '2021.03.07 21:30:00', 8: '2021.03.08 01:45:00', 9: '2021.03.08 05:45:00'}}
{'Il': {142738: 'ankara', 142739: 'ankara', 142740: 'ankara', 142741: 'ankara', 142742: 'ankara', 142743: 'ankara', 142744: 'ankara', 142745: 'ankara', 142746: 'ankara', 142747: 'ankara', 142748: 'ankara', 142749: 'ankara', 142750: 'ankara', 142751: 'ankara', 142752: 'ankara', 142753: 'ankara', 142754: 'ankara', 142755: 'ankara', 142756: 'ankara', 142757: 'ankara', 142758: 'ankara', 142759: 'ankara', 142760: 'ankara', 142761: 'ankara', 142762: 'ankara', 142763: 'ankara', 142764: 'ankara', 142765: 'ankara', 142766: 'ankara', 142767: 'ankara', 142768: 'ankara', 142769: 'ankara', 142770: 'ankara', 142771: 'ankara', 142772: 'ankara', 142773: 'ankara', 142774: 'ankara', 142775: 'ankara', 142776: 'ankara', 142777: 'ankara'}, 'Lat': {142738: 40.13, 142739: 40.13, 142740: 40.13, 142741: 40.13, 142742: 40.13, 142743: 40.13, 142744: 40.13, 142745: 40.13, 142746: 40.13, 142747: 40.13, 142748: 40.13, 142749: 40.13, 142750: 40.13, 142751: 40.13, 142752: 40.13, 142753: 40.13, 142754: 40.13, 142755: 40.13, 142756: 40.13, 142757: 40.13, 142758: 40.13, 142759: 40.13, 142760: 40.13, 142761: 40.13, 142762: 40.13, 142763: 40.13, 142764: 40.13, 142765: 40.13, 142766: 40.13, 142767: 40.13, 142768: 40.13, 142769: 40.13, 142770: 40.13, 142771: 40.13, 142772: 40.13, 142773: 40.13, 142774: 40.13, 142775: 40.13, 142776: 40.13, 142777: 40.13}, 'Lon': {142738: 33.1, 142739: 33.1, 142740: 33.1, 142741: 33.1, 142742: 33.1, 142743: 33.1, 142744: 33.1, 142745: 33.1, 142746: 33.1, 142747: 33.1, 142748: 33.1, 142749: 33.1, 142750: 33.1, 142751: 33.1, 142752: 33.1, 142753: 33.1, 142754: 33.1, 142755: 33.1, 142756: 33.1, 142757: 33.1, 142758: 33.1, 142759: 33.1, 142760: 33.1, 142761: 33.1, 142762: 33.1, 142763: 33.1, 142764: 33.1, 142765: 33.1, 142766: 33.1, 142767: 33.1, 142768: 33.1, 142769: 33.1, 142770: 33.1, 142771: 33.1, 142772: 33.1, 142773: 33.1, 142774: 33.1, 142775: 33.1, 142776: 33.1, 142777: 33.1}, 'Tarih': {142738: '2021.03.07', 142739: '2021.03.07', 142740: '2021.03.07', 142741: '2021.03.07', 142742: '2021.03.07', 142743: '2021.03.07', 142744: '2021.03.07', 142745: '2021.03.07', 142746: '2021.03.07', 142747: '2021.03.07', 142748: '2021.03.07', 142749: '2021.03.07', 142750: '2021.03.07', 142751: '2021.03.07', 142752: '2021.03.07', 142753: '2021.03.07', 142754: '2021.03.07', 142755: '2021.03.07', 142756: '2021.03.07', 142757: '2021.03.07', 142758: '2021.03.07', 142759: '2021.03.07', 142760: '2021.03.07', 142761: '2021.03.08', 142762: '2021.03.08', 142763: '2021.03.08', 142764: '2021.03.08', 142765: '2021.03.08', 142766: '2021.03.08', 142767: '2021.03.08', 142768: '2021.03.08', 142769: '2021.03.08', 142770: '2021.03.08', 142771: '2021.03.08', 142772: '2021.03.08', 142773: '2021.03.08', 142774: '2021.03.08', 142775: '2021.03.08', 142776: '2021.03.08', 142777: '2021.03.08'}, 'Saat': {142738: '00:00', 142739: '03:00', 142740: '06:00', 142741: '09:00', 142742: '12:00', 142743: '15:00', 142744: '18:00', 142745: '21:00', 142746: '00:00', 142747: '03:00', 142748: '06:00', 142749: '09:00', 142750: '12:00', 142751: '15:00', 142752: '18:00', 142753: '21:00', 142754: '00:00', 142755: '03:00', 142756: '06:00', 142757: '09:00', 142758: '12:00', 142759: '15:00', 142760: '18:00', 142761: '00:00', 142762: '03:00', 142763: '06:00', 142764: '09:00', 142765: '12:00', 142766: '15:00', 142767: '18:00', 142768: '21:00', 142769: '00:00', 142770: '03:00', 142771: '06:00', 142772: '09:00', 142773: '12:00', 142774: '15:00', 142775: '18:00', 142776: '21:00', 142777: '00:00'}, 'Weather': {142738: 1, 142739: 1, 142740: 1, 142741: 1, 142742: 1, 142743: 5, 142744: 5, 142745: 1, 142746: 1, 142747: 1, 142748: 5, 142749: 5, 142750: 11, 142751: 5, 142752: 5, 142753: 1, 142754: 7, 142755: 7, 142756: 4, 142757: 4, 142758: 4, 142759: 1, 142760: 4, 142761: 1, 142762: 1, 142763: 1, 142764: 1, 142765: 1, 142766: 5, 142767: 5, 142768: 1, 142769: 1, 142770: 1, 142771: 5, 142772: 5, 142773: 11, 142774: 5, 142775: 5, 142776: 1, 142777: 7}, 'Temp': {142738: 22, 142739: 17, 142740: 18, 142741: 24, 142742: 28, 142743: 28, 142744: 24, 142745: 22, 142746: 18, 142747: 18, 142748: 19, 142749: 22, 142750: 26, 142751: 25, 142752: 21, 142753: 17, 142754: 28, 142755: 21, 142756: 22, 142757: 28, 142758: 32, 142759: 34, 142760: 32, 142761: 22, 142762: 17, 142763: 18, 142764: 24, 142765: 28, 142766: 28, 142767: 24, 142768: 22, 142769: 18, 142770: 18, 142771: 19, 142772: 22, 142773: 26, 142774: 25, 142775: 21, 142776: 17, 142777: 28}, 'Feels': {142738: 22, 142739: 17, 142740: 18, 142741: 25, 142742: 28, 142743: 27, 142744: 25, 142745: 22, 142746: 18, 142747: 18, 142748: 19, 142749: 23, 142750: 26, 142751: 26, 142752: 21, 142753: 17, 142754: 31, 142755: 21, 142756: 22, 142757: 26, 142758: 30, 142759: 31, 142760: 31, 142761: 22, 142762: 17, 142763: 18, 142764: 25, 142765: 28, 142766: 27, 142767: 25, 142768: 22, 142769: 18, 142770: 18, 142771: 19, 142772: 23, 142773: 26, 142774: 26, 142775: 21, 142776: 17, 142777: 31}, 'Wind': {142738: nan, 142739: nan, 142740: nan, 142741: nan, 142742: nan, 142743: nan, 142744: nan, 142745: nan, 142746: nan, 142747: nan, 142748: nan, 142749: nan, 142750: nan, 142751: nan, 142752: nan, 142753: nan, 142754: nan, 142755: nan, 142756: nan, 142757: nan, 142758: nan, 142759: nan, 142760: nan, 142761: nan, 142762: nan, 142763: nan, 142764: nan, 142765: nan, 142766: nan, 142767: nan, 142768: nan, 142769: nan, 142770: nan, 142771: nan, 142772: nan, 142773: nan, 142774: nan, 142775: nan, 142776: nan, 142777: nan}, 'Gust': {142738: 13, 142739: 14, 142740: 13, 142741: 11, 142742: 15, 142743: 19, 142744: 25, 142745: 19, 142746: 15, 142747: 14, 142748: 10, 142749: 7, 142750: 8, 142751: 7, 142752: 9, 142753: 17, 142754: 26, 142755: 18, 142756: 17, 142757: 14, 142758: 14, 142759: 14, 142760: 24, 142761: 13, 142762: 14, 142763: 13, 142764: 11, 142765: 15, 142766: 19, 142767: 25, 142768: 19, 142769: 15, 142770: 14, 142771: 10, 142772: 7, 142773: 8, 142774: 7, 142775: 9, 142776: 17, 142777: 26}, 'Rain': {142738: 0.0, 142739: 0.0, 142740: 0.0, 142741: 0.0, 142742: 0.0, 142743: 0.1, 142744: 0.2, 142745: 0.1, 142746: 0.0, 142747: 0.0, 142748: 0.1, 142749: 0.5, 142750: 1.2, 142751: 1.0, 142752: 0.3, 142753: 0.2, 142754: 0.0, 142755: 0.0, 142756: 0.0, 142757: 0.0, 142758: 0.0, 142759: 0.0, 142760: 0.0, 142761: 0.0, 142762: 0.0, 142763: 0.0, 142764: 0.0, 142765: 0.0, 142766: 0.1, 142767: 0.2, 142768: 0.1, 142769: 0.0, 142770: 0.0, 142771: 0.1, 142772: 0.5, 142773: 1.2, 142774: 1.0, 142775: 0.3, 142776: 0.2, 142777: 0.0}, 'Humidity': {142738: '74%', 142739: '78%', 142740: '70%', 142741: '45%', 142742: '32%', 142743: '33%', 142744: '49%', 142745: '62%', 142746: '74%', 142747: '75%', 142748: '72%', 142749: '61%', 142750: '46%', 142751: '48%', 142752: '63%', 142753: '61%', 142754: '33%', 142755: '42%', 142756: '39%', 142757: '24%', 142758: '18%', 142759: '17%', 142760: '18%', 142761: '74%', 142762: '78%', 142763: '70%', 142764: '45%', 142765: '32%', 142766: '33%', 142767: '49%', 142768: '62%', 142769: '74%', 142770: '75%', 142771: '72%', 142772: '61%', 142773: '46%', 142774: '48%', 142775: '63%', 142776: '61%', 142777: '33%'}, 'Cloud': {142738: nan, 142739: nan, 142740: nan, 142741: nan, 142742: nan, 142743: nan, 142744: nan, 142745: nan, 142746: nan, 142747: nan, 142748: nan, 142749: nan, 142750: nan, 142751: nan, 142752: nan, 142753: nan, 142754: nan, 142755: nan, 142756: nan, 142757: nan, 142758: nan, 142759: nan, 142760: nan, 142761: nan, 142762: nan, 142763: nan, 142764: nan, 142765: nan, 142766: nan, 142767: nan, 142768: nan, 142769: nan, 142770: nan, 142771: nan, 142772: nan, 142773: nan, 142774: nan, 142775: nan, 142776: nan, 142777: nan}, 'Presure': {142738: 1011, 142739: 1012, 142740: 1012, 142741: 1012, 142742: 1011, 142743: 1011, 142744: 1013, 142745: 1014, 142746: 1013, 142747: 1014, 142748: 1014, 142749: 1014, 142750: 1013, 142751: 1012, 142752: 1013, 142753: 1013, 142754: 1009, 142755: 1009, 142756: 1009, 142757: 1008, 142758: 1005, 142759: 1003, 142760: 1003, 142761: 1011, 142762: 1012, 142763: 1012, 142764: 1012, 142765: 1011, 142766: 1011, 142767: 1013, 142768: 1014, 142769: 1013, 142770: 1014, 142771: 1014, 142772: 1014, 142773: 1013, 142774: 1012, 142775: 1013, 142776: 1013, 142777: 1009}, 'Vis': {142738: nan, 142739: nan, 142740: nan, 142741: nan, 142742: nan, 142743: nan, 142744: nan, 142745: nan, 142746: nan, 142747: nan, 142748: nan, 142749: nan, 142750: nan, 142751: nan, 142752: nan, 142753: nan, 142754: nan, 142755: nan, 142756: nan, 142757: nan, 142758: nan, 142759: nan, 142760: nan, 142761: nan, 142762: nan, 142763: nan, 142764: nan, 142765: nan, 142766: nan, 142767: nan, 142768: nan, 142769: nan, 142770: nan, 142771: nan, 142772: nan, 142773: nan, 142774: nan, 142775: nan, 142776: nan, 142777: nan}}
for i in range(df.date.count()): for n in range(df2.Date.count()): if df.date[i][0:10]==df2.Date[n]: if pd.Timestamp(df.date[i][11:16]).round('180min').to_pydatetime()==df2.Time[n]: df['Weather'][i]=df2['Weather'][n] df['Temp'][i]=df2['Temp'][n] df['Feels'][i]=df2['Feels'][n] df['Wind'][i]=df2['Wind'][n] df['Gust'][i]=df2['Gust'][n] df['Rain'][i]=df2['Rain'][n] df['Humidity'][i]=df2['Humidity'][n] df['Cloud'][i]=df2['Cloud'][n] df['Presure'][i]=df2['Presure'][n] df['Vis'][i]=df2['Vis'][n]
Advertisement
Answer
Creation of the first dataframe:
df1 = pd.DataFrame({'road': {0: 10500, 1: 10500, 2: 10500, 3: 105400, 4: 105400, 5: 106600, 6: 14100, 7: 22800, 8: 22800, 9: 22800}, 'date': {0: '2021.03.08 02:00:00', 1: '2021.03.08 05:45:00', 2: '2021.03.08 04:15:00', 3: '2021.03.07 21:30:00', 4: '2021.03.08 05:45:00', 5: '2021.03.08 05:45:00', 6: '2021.03.07 21:30:00', 7: '2021.03.07 21:30:00', 8: '2021.03.08 01:45:00', 9: '2021.03.08 05:45:00'}}) df1['date'] = pd.to_datetime(df1['date']) df1 = df1.sort_values(by = 'date')
road date 3 105400 2021-03-07 21:30:00 6 14100 2021-03-07 21:30:00 7 22800 2021-03-07 21:30:00 8 22800 2021-03-08 01:45:00 0 10500 2021-03-08 02:00:00 2 10500 2021-03-08 04:15:00 1 10500 2021-03-08 05:45:00 4 105400 2021-03-08 05:45:00 5 106600 2021-03-08 05:45:00 9 22800 2021-03-08 05:45:00
Creation of the second dataframe:
df2 = pd.DataFrame({'Il': {142738: 'ankara', 142739: 'ankara', 142740: 'ankara', 142741: 'ankara', 142742: 'ankara', 142743: 'ankara', 142744: 'ankara', 142745: 'ankara', 142746: 'ankara', 142747: 'ankara', 142748: 'ankara', 142749: 'ankara', 142750: 'ankara', 142751: 'ankara', 142752: 'ankara', 142753: 'ankara', 142754: 'ankara', 142755: 'ankara', 142756: 'ankara', 142757: 'ankara', 142758: 'ankara', 142759: 'ankara', 142760: 'ankara', 142761: 'ankara', 142762: 'ankara', 142763: 'ankara', 142764: 'ankara', 142765: 'ankara', 142766: 'ankara', 142767: 'ankara', 142768: 'ankara', 142769: 'ankara', 142770: 'ankara', 142771: 'ankara', 142772: 'ankara', 142773: 'ankara', 142774: 'ankara', 142775: 'ankara', 142776: 'ankara', 142777: 'ankara'}, 'Lat': {142738: 40.13, 142739: 40.13, 142740: 40.13, 142741: 40.13, 142742: 40.13, 142743: 40.13, 142744: 40.13, 142745: 40.13, 142746: 40.13, 142747: 40.13, 142748: 40.13, 142749: 40.13, 142750: 40.13, 142751: 40.13, 142752: 40.13, 142753: 40.13, 142754: 40.13, 142755: 40.13, 142756: 40.13, 142757: 40.13, 142758: 40.13, 142759: 40.13, 142760: 40.13, 142761: 40.13, 142762: 40.13, 142763: 40.13, 142764: 40.13, 142765: 40.13, 142766: 40.13, 142767: 40.13, 142768: 40.13, 142769: 40.13, 142770: 40.13, 142771: 40.13, 142772: 40.13, 142773: 40.13, 142774: 40.13, 142775: 40.13, 142776: 40.13, 142777: 40.13}, 'Lon': {142738: 33.1, 142739: 33.1, 142740: 33.1, 142741: 33.1, 142742: 33.1, 142743: 33.1, 142744: 33.1, 142745: 33.1, 142746: 33.1, 142747: 33.1, 142748: 33.1, 142749: 33.1, 142750: 33.1, 142751: 33.1, 142752: 33.1, 142753: 33.1, 142754: 33.1, 142755: 33.1, 142756: 33.1, 142757: 33.1, 142758: 33.1, 142759: 33.1, 142760: 33.1, 142761: 33.1, 142762: 33.1, 142763: 33.1, 142764: 33.1, 142765: 33.1, 142766: 33.1, 142767: 33.1, 142768: 33.1, 142769: 33.1, 142770: 33.1, 142771: 33.1, 142772: 33.1, 142773: 33.1, 142774: 33.1, 142775: 33.1, 142776: 33.1, 142777: 33.1}, 'Tarih': {142738: '2021.03.07', 142739: '2021.03.07', 142740: '2021.03.07', 142741: '2021.03.07', 142742: '2021.03.07', 142743: '2021.03.07', 142744: '2021.03.07', 142745: '2021.03.07', 142746: '2021.03.07', 142747: '2021.03.07', 142748: '2021.03.07', 142749: '2021.03.07', 142750: '2021.03.07', 142751: '2021.03.07', 142752: '2021.03.07', 142753: '2021.03.07', 142754: '2021.03.07', 142755: '2021.03.07', 142756: '2021.03.07', 142757: '2021.03.07', 142758: '2021.03.07', 142759: '2021.03.07', 142760: '2021.03.07', 142761: '2021.03.08', 142762: '2021.03.08', 142763: '2021.03.08', 142764: '2021.03.08', 142765: '2021.03.08', 142766: '2021.03.08', 142767: '2021.03.08', 142768: '2021.03.08', 142769: '2021.03.08', 142770: '2021.03.08', 142771: '2021.03.08', 142772: '2021.03.08', 142773: '2021.03.08', 142774: '2021.03.08', 142775: '2021.03.08', 142776: '2021.03.08', 142777: '2021.03.08'}, 'Saat': {142738: '00:00', 142739: '03:00', 142740: '06:00', 142741: '09:00', 142742: '12:00', 142743: '15:00', 142744: '18:00', 142745: '21:00', 142746: '00:00', 142747: '03:00', 142748: '06:00', 142749: '09:00', 142750: '12:00', 142751: '15:00', 142752: '18:00', 142753: '21:00', 142754: '00:00', 142755: '03:00', 142756: '06:00', 142757: '09:00', 142758: '12:00', 142759: '15:00', 142760: '18:00', 142761: '00:00', 142762: '03:00', 142763: '06:00', 142764: '09:00', 142765: '12:00', 142766: '15:00', 142767: '18:00', 142768: '21:00', 142769: '00:00', 142770: '03:00', 142771: '06:00', 142772: '09:00', 142773: '12:00', 142774: '15:00', 142775: '18:00', 142776: '21:00', 142777: '00:00'}, 'Weather': {142738: 1, 142739: 1, 142740: 1, 142741: 1, 142742: 1, 142743: 5, 142744: 5, 142745: 1, 142746: 1, 142747: 1, 142748: 5, 142749: 5, 142750: 11, 142751: 5, 142752: 5, 142753: 1, 142754: 7, 142755: 7, 142756: 4, 142757: 4, 142758: 4, 142759: 1, 142760: 4, 142761: 1, 142762: 1, 142763: 1, 142764: 1, 142765: 1, 142766: 5, 142767: 5, 142768: 1, 142769: 1, 142770: 1, 142771: 5, 142772: 5, 142773: 11, 142774: 5, 142775: 5, 142776: 1, 142777: 7}, 'Temp': {142738: 22, 142739: 17, 142740: 18, 142741: 24, 142742: 28, 142743: 28, 142744: 24, 142745: 22, 142746: 18, 142747: 18, 142748: 19, 142749: 22, 142750: 26, 142751: 25, 142752: 21, 142753: 17, 142754: 28, 142755: 21, 142756: 22, 142757: 28, 142758: 32, 142759: 34, 142760: 32, 142761: 22, 142762: 17, 142763: 18, 142764: 24, 142765: 28, 142766: 28, 142767: 24, 142768: 22, 142769: 18, 142770: 18, 142771: 19, 142772: 22, 142773: 26, 142774: 25, 142775: 21, 142776: 17, 142777: 28}, 'Feels': {142738: 22, 142739: 17, 142740: 18, 142741: 25, 142742: 28, 142743: 27, 142744: 25, 142745: 22, 142746: 18, 142747: 18, 142748: 19, 142749: 23, 142750: 26, 142751: 26, 142752: 21, 142753: 17, 142754: 31, 142755: 21, 142756: 22, 142757: 26, 142758: 30, 142759: 31, 142760: 31, 142761: 22, 142762: 17, 142763: 18, 142764: 25, 142765: 28, 142766: 27, 142767: 25, 142768: 22, 142769: 18, 142770: 18, 142771: 19, 142772: 23, 142773: 26, 142774: 26, 142775: 21, 142776: 17, 142777: 31}, 'Wind': {142738: np.nan, 142739: np.nan, 142740: np.nan, 142741: np.nan, 142742: np.nan, 142743: np.nan, 142744: np.nan, 142745: np.nan, 142746: np.nan, 142747: np.nan, 142748: np.nan, 142749: np.nan, 142750: np.nan, 142751: np.nan, 142752: np.nan, 142753: np.nan, 142754: np.nan, 142755: np.nan, 142756: np.nan, 142757: np.nan, 142758: np.nan, 142759: np.nan, 142760: np.nan, 142761: np.nan, 142762: np.nan, 142763: np.nan, 142764: np.nan, 142765: np.nan, 142766: np.nan, 142767: np.nan, 142768: np.nan, 142769: np.nan, 142770: np.nan, 142771: np.nan, 142772: np.nan, 142773: np.nan, 142774: np.nan, 142775: np.nan, 142776: np.nan, 142777: np.nan}, 'Gust': {142738: 13, 142739: 14, 142740: 13, 142741: 11, 142742: 15, 142743: 19, 142744: 25, 142745: 19, 142746: 15, 142747: 14, 142748: 10, 142749: 7, 142750: 8, 142751: 7, 142752: 9, 142753: 17, 142754: 26, 142755: 18, 142756: 17, 142757: 14, 142758: 14, 142759: 14, 142760: 24, 142761: 13, 142762: 14, 142763: 13, 142764: 11, 142765: 15, 142766: 19, 142767: 25, 142768: 19, 142769: 15, 142770: 14, 142771: 10, 142772: 7, 142773: 8, 142774: 7, 142775: 9, 142776: 17, 142777: 26}, 'Rain': {142738: 0.0, 142739: 0.0, 142740: 0.0, 142741: 0.0, 142742: 0.0, 142743: 0.1, 142744: 0.2, 142745: 0.1, 142746: 0.0, 142747: 0.0, 142748: 0.1, 142749: 0.5, 142750: 1.2, 142751: 1.0, 142752: 0.3, 142753: 0.2, 142754: 0.0, 142755: 0.0, 142756: 0.0, 142757: 0.0, 142758: 0.0, 142759: 0.0, 142760: 0.0, 142761: 0.0, 142762: 0.0, 142763: 0.0, 142764: 0.0, 142765: 0.0, 142766: 0.1, 142767: 0.2, 142768: 0.1, 142769: 0.0, 142770: 0.0, 142771: 0.1, 142772: 0.5, 142773: 1.2, 142774: 1.0, 142775: 0.3, 142776: 0.2, 142777: 0.0}, 'Humidity': {142738: '74%', 142739: '78%', 142740: '70%', 142741: '45%', 142742: '32%', 142743: '33%', 142744: '49%', 142745: '62%', 142746: '74%', 142747: '75%', 142748: '72%', 142749: '61%', 142750: '46%', 142751: '48%', 142752: '63%', 142753: '61%', 142754: '33%', 142755: '42%', 142756: '39%', 142757: '24%', 142758: '18%', 142759: '17%', 142760: '18%', 142761: '74%', 142762: '78%', 142763: '70%', 142764: '45%', 142765: '32%', 142766: '33%', 142767: '49%', 142768: '62%', 142769: '74%', 142770: '75%', 142771: '72%', 142772: '61%', 142773: '46%', 142774: '48%', 142775: '63%', 142776: '61%', 142777: '33%'}, 'Cloud': {142738: np.nan, 142739: np.nan, 142740: np.nan, 142741: np.nan, 142742: np.nan, 142743: np.nan, 142744: np.nan, 142745: np.nan, 142746: np.nan, 142747: np.nan, 142748: np.nan, 142749: np.nan, 142750: np.nan, 142751: np.nan, 142752: np.nan, 142753: np.nan, 142754: np.nan, 142755: np.nan, 142756: np.nan, 142757: np.nan, 142758: np.nan, 142759: np.nan, 142760: np.nan, 142761: np.nan, 142762: np.nan, 142763: np.nan, 142764: np.nan, 142765: np.nan, 142766: np.nan, 142767: np.nan, 142768: np.nan, 142769: np.nan, 142770: np.nan, 142771: np.nan, 142772: np.nan, 142773: np.nan, 142774: np.nan, 142775: np.nan, 142776: np.nan, 142777: np.nan}, 'Presure': {142738: 1011, 142739: 1012, 142740: 1012, 142741: 1012, 142742: 1011, 142743: 1011, 142744: 1013, 142745: 1014, 142746: 1013, 142747: 1014, 142748: 1014, 142749: 1014, 142750: 1013, 142751: 1012, 142752: 1013, 142753: 1013, 142754: 1009, 142755: 1009, 142756: 1009, 142757: 1008, 142758: 1005, 142759: 1003, 142760: 1003, 142761: 1011, 142762: 1012, 142763: 1012, 142764: 1012, 142765: 1011, 142766: 1011, 142767: 1013, 142768: 1014, 142769: 1013, 142770: 1014, 142771: 1014, 142772: 1014, 142773: 1013, 142774: 1012, 142775: 1013, 142776: 1013, 142777: 1009}, 'Vis': {142738: np.nan, 142739: np.nan, 142740: np.nan, 142741: np.nan, 142742: np.nan, 142743: np.nan, 142744: np.nan, 142745: np.nan, 142746: np.nan, 142747: np.nan, 142748: np.nan, 142749: np.nan, 142750: np.nan, 142751: np.nan, 142752: np.nan, 142753: np.nan, 142754: np.nan, 142755: np.nan, 142756: np.nan, 142757: np.nan, 142758: np.nan, 142759: np.nan, 142760: np.nan, 142761: np.nan, 142762: np.nan, 142763: np.nan, 142764: np.nan, 142765: np.nan, 142766: np.nan, 142767: np.nan, 142768: np.nan, 142769: np.nan, 142770: np.nan, 142771: np.nan, 142772: np.nan, 142773: np.nan, 142774: np.nan, 142775: np.nan, 142776: np.nan, 142777: np.nan}}) df2['date'] = df2['Tarih'] + ' ' + df2['Saat'] df2['date'] = pd.to_datetime(df2['date']) df2 = df2.sort_values(by = 'date')
Il Lat Lon Tarih Saat Weather Temp Feels Wind Gust Rain Humidity Cloud Presure Vis date 142738 ankara 40.13 33.1 2021.03.07 00:00 1 22 22 NaN 13 0.0 74% NaN 1011 NaN 2021-03-07 00:00:00 142754 ankara 40.13 33.1 2021.03.07 00:00 7 28 31 NaN 26 0.0 33% NaN 1009 NaN 2021-03-07 00:00:00 142746 ankara 40.13 33.1 2021.03.07 00:00 1 18 18 NaN 15 0.0 74% NaN 1013 NaN 2021-03-07 00:00:00 142739 ankara 40.13 33.1 2021.03.07 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN 2021-03-07 03:00:00 142755 ankara 40.13 33.1 2021.03.07 03:00 7 21 21 NaN 18 0.0 42% NaN 1009 NaN 2021-03-07 03:00:00 142747 ankara 40.13 33.1 2021.03.07 03:00 1 18 18 NaN 14 0.0 75% NaN 1014 NaN 2021-03-07 03:00:00 142740 ankara 40.13 33.1 2021.03.07 06:00 1 18 18 NaN 13 0.0 70% NaN 1012 NaN 2021-03-07 06:00:00 142756 ankara 40.13 33.1 2021.03.07 06:00 4 22 22 NaN 17 0.0 39% NaN 1009 NaN 2021-03-07 06:00:00 142748 ankara 40.13 33.1 2021.03.07 06:00 5 19 19 NaN 10 0.1 72% NaN 1014 NaN 2021-03-07 06:00:00 142749 ankara 40.13 33.1 2021.03.07 09:00 5 22 23 NaN 7 0.5 61% NaN 1014 NaN 2021-03-07 09:00:00
Merge through
pandas.merge_asof
:df = pd.merge_asof(left = df1, right = df2, on = 'date', tolerance = pd.Timedelta('180min'))
road date Il Lat Lon Tarih Saat Weather Temp Feels Wind Gust Rain Humidity Cloud Presure Vis 0 105400 2021-03-07 21:30:00 ankara 40.13 33.1 2021.03.07 21:00 1 22 22 NaN 19 0.1 62% NaN 1014 NaN 1 14100 2021-03-07 21:30:00 ankara 40.13 33.1 2021.03.07 21:00 1 22 22 NaN 19 0.1 62% NaN 1014 NaN 2 22800 2021-03-07 21:30:00 ankara 40.13 33.1 2021.03.07 21:00 1 22 22 NaN 19 0.1 62% NaN 1014 NaN 3 22800 2021-03-08 01:45:00 ankara 40.13 33.1 2021.03.08 00:00 1 22 22 NaN 13 0.0 74% NaN 1011 NaN 4 10500 2021-03-08 02:00:00 ankara 40.13 33.1 2021.03.08 00:00 1 22 22 NaN 13 0.0 74% NaN 1011 NaN 5 10500 2021-03-08 04:15:00 ankara 40.13 33.1 2021.03.08 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN 6 10500 2021-03-08 05:45:00 ankara 40.13 33.1 2021.03.08 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN 7 105400 2021-03-08 05:45:00 ankara 40.13 33.1 2021.03.08 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN 8 106600 2021-03-08 05:45:00 ankara 40.13 33.1 2021.03.08 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN 9 22800 2021-03-08 05:45:00 ankara 40.13 33.1 2021.03.08 03:00 1 17 17 NaN 14 0.0 78% NaN 1012 NaN