使用Python比较Excel中的2列

发布于 2025-01-23 02:22:11 字数 223 浏览 1 评论 0原文

您好,我有一个带有2列数据的Excel文件(.xlsx),我想将列A中的行与B列中的行进行比较,并在另一个生成的Excel文件中输出B列的值,其中行A a为空。

任何帮助都将不胜感激

excel文件在a和a列中显示数据

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2025-01-30 02:22:11

此代码段应该可以解决:

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文