'Compare 2 columns in excel using python

Hello I have an excel file (.xlsx) with 2 columns of data I want to compare the rows in column A with column B and output the value of column B in another generated excel file where the rows column A are empty.

Any Help would be greatly appreciated

Excel file showing data in column A and column B



Solution 1:[1]

This code snippet should do the trick:

import pandas as pd

df = pd.read_excel(io="file.xlsx", header=0)
df = df[df['A'].isna()]
df.to_excel("new_file.xlsx", columns=['B'], index=False)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1