Relative Content

Tag Archive for python-3.xpandas

Dataframe with FROM and TO column. Unordered, Get correct combinations

df = pd.DataFrame({ ‘from’: [‘Start’, ’21’, ’73’, ‘Start’, ’55’, ‘1’, ‘2’, ‘3’], ‘to’: [’21’, ’73’, ’55’, ‘1’, ’54’, ‘2’, ‘3’, ‘4’] }) from to 0 Start 21 1 21 73 2 73 55 3 Start 1 4 55 54 5 1 2 6 2 3 7 3 4 desired output [[‘Start’, ’21’, ’73’, ’55’, ’54’], […]

How to efficiently compare 2 dataframe and produce a column value based on condition

data1 = { ‘alias_cd’: [‘12345’, ‘12345’, ‘12345’], ‘country_cd’: [‘AU’, ‘AU’, ‘AU2’], ‘pos_name’: [‘st1’, ‘Jh’, ‘Jh’], ‘ts_allocated’: [100, 100, 100], ‘tr_id’: [‘None’, ‘None’, ‘None’], ‘ty_name’: [‘E2E’, ‘E2E’, ‘E2E’] } data2 = { ‘alias_cd’: [‘12345’, ‘12345’], ‘country_cd’: [‘AU’, ‘AU3’], ‘pos_name’: [‘st1’, ‘st2’], ‘ts_allocated’: [200, 100], ‘tr_id’: [‘None’, ‘None’], ‘ty_name’: [‘E2E’, ‘E2E’] } df1 = pd.DataFrame(data1) df2 = […]