How to merge two dataframes based on the condition of a startdate and enddate?

Advertisements I have this df1 library(dplyr) library(tidyverse) df1 = data.frame(ID = c(100,101,101,102,102,103,103,104,104,105,106), x_line = c(1,1,2,1,2,1,2,1,2,1,1), start_date = c(’04/01/2018′,’05/01/2019′,’25/08/2021′,’08/03/2017′,’07/08/2018′, ’09/04/2016′,’29/12/2018′,’04/08/2018′,’03/05/2022′,’04/01/2018′,’04/01/2018′), end_date = c(’04/05/2019′,’07/02/2020′,’27/09/2021′,’18/07/2018′,’17/10/2019′, ’19/12/2018′,’22/12/2019′,’14/09/2021′,’26/12/2022′,’15/02/2020′,’24/08/2020′) ) and the following df2 df2 = data.frame(ID = c(100,100,100,101,101,102,102,103,103,104,104,105,105,106,106,106), product_name = c(‘AA’,’BB’,’CC’,’AA’,’CC’,’DD’,’EE’,’DD’,’FF’, ‘AA’,’FF’,’DD’,’AA’,’CC’,’AA’,’BB’), start_taken_date = c(’04/05/2018′,’25/08/2018′,’27/09/2018′,’18/07/2019′,’25/11/2019′, ’29/01/2018′,’07/09/2018′,’14/09/2017′,’01/01/2019′,’15/02/2019′,’24/08/2020′, ’04/03/2019′,’04/08/2018′, ’05/05/2018′,’06/06/2019′,’08/09/2018′), end_taken_date = c(’01/05/2019′,’26/09/2018′,’25/03/2019′,’25/09/2019′,’02/01/2020′, ’19/06/2018′,’22/09/2019′,’16/01/2018′,’04/03/2019′,’25/06/2022′,’23/07/2022′, ’05/04/2019′,’05/09/2018′, ’29/03/2019′,’07/07/2019′,’04/05/2020′)) df3 is the result of merging… Read More How to merge two dataframes based on the condition of a startdate and enddate?

Merge not giving the desired result when replacing values in a dataframe based on a match in another dataframe

Advertisements I’m trying to replace values in a dataframe based on values in a different dataframe. Below you will find a simple data sample: df1 old_index Date 0 3 2019-10-23 1 19 2019-12-05 2 29 NaT 3 32 NaT 4 34 2019-12-05 5 116 NaT 6 118 2020-01-29 df2 old_index Date 4 3 2019-10-24 12… Read More Merge not giving the desired result when replacing values in a dataframe based on a match in another dataframe

Pandas create a new column based on exact match of text values

Advertisements I have two dataframes that look like below proj_df = pd.DataFrame({‘reg_id’:[1,2,3,4], ‘part_no’:[‘P1′,’P2′,’P3′,’P4’], ‘partner’:[‘A’,’B’,’C’,’D’], ‘cust_name_1’: [‘ABC PVT LTD’,’Tesla’,’Apple’,’Google’], ‘cust_name_2’:[‘ABC’,’Tesla Ltd’,’Apple Inc’,’Google Enterprises’], ‘cust_name_3’:[‘ABC’,’Tesla America’,’Apple America’,’Google Ent Pvt ltd’]}) data_df = pd.DataFrame({‘cust_name’: [‘ABC’,’Tesla America’,’Apple Inc’,’Google’,’Google’,’ABC’], ‘partner’:[‘A’,’B’,’C’,’D’,’E’,’A’], ‘part_no’:[‘P1′,’P2′,’P3′,’P4′,’P5′,’P6’], ‘qty’:[100,100,600,150,320,410]}) I would like to do the below a) Identify the exactly matching customer name column from proj_df by… Read More Pandas create a new column based on exact match of text values

Merge two or more lines of text into one line with python pandas

Advertisements I have a txt file like below, 140037|1|TOP SOIL DARK BROWN CLAY RICH ORGANIC|0|0.8 140037|2|MATER SOFT|| 140037|3|SANDY CLAY SOFT MOTTLED GREY/ORANGE|0.8|1 140037|4|BROWN <15% SAND GRAINS|| 140037|5|CLAY MOTTLED DARK GREY/ORANGE BROWN|1|3 140037|6|SOFT BECOMING FIRM MINOR SILT AND|| 140037|7|FINE SAND IN SOME LAYERS|| and want to make it like this. 140037|1|TOP SOIL DARK BROWN CLAY RICH… Read More Merge two or more lines of text into one line with python pandas

Pandas: Update master dataframe with additional columns, with growing number of common columns in subsequent merges

Advertisements I’m trying to figure out how to achieve the following. Say that I have a master dataframe with an ID column and various other data: ID A B C 01 1x 1y 1z 02 2x 2y 2z 03 3x 3y 3z 04 4x 4y 4z … 01000 01000x 01000y 01000z And I additionally have… Read More Pandas: Update master dataframe with additional columns, with growing number of common columns in subsequent merges