Pandas Merge is not showing Values, though I have a common column in 2 data frames

Issue

This Content is from Stack Overflow. Question asked by Krishna

I want to extract lines which are not matching in both the sheets based on column called “KeyValue” and that column value is the concat of columns (‘WeekStartDate’,’EmployeeName’,’ScheduleType’,’Day1′,’CenterCode’) in both the sheets.

However I am getting no merged values, it shows values from both DFs on top of each other despite having common Column & value in it. here is my code and result.

import pandas as pd

import numpy as np

df = pd.read_csv(‘Vinay1.csv’)
#print(df.info())

df1 = pd.read_csv(‘Maddy1.csv’)
#print(df1.info())

Test1 = pd.merge(df, df1, on=’KeyValue’, how=’outer’)
#Test1.to_csv(‘MergedData1.csv’)

#Test2 = DataIO.join(Maddy.set_index(‘KeyValue’), on=’POST’)
print(Test1)
Test1.to_csv(‘MergedData2.csv’)

================================================================

Output:
Unnamed: 0_x RowID … WeekStartDate_y Day1_y
0 0.0 1.0 … NaN NaN
1 1.0 2.0 … NaN NaN
2 2.0 3.0 … NaN NaN
3 3.0 4.0 … NaN NaN
4 4.0 5.0 … NaN NaN
.. … … … … …
194 NaN NaN … 10-01-2022 11:00AM-05:00PM
195 NaN NaN … 10-02-2022 10:00AM-05:00PM
196 NaN NaN … 10-01-2022 09:00AM-05:00PM
197 NaN NaN … 10-02-2022 10:00AM-05:00PM
198 NaN NaN … NaN NaN

[199 rows x 28 columns]
[Finished in 0.7s]

Note: here are my two csv sheets that I am using to compare & merge.

Vinay1 – this sheet is used as df

Maddy1 – This sheet is used as df1



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?