使用python从列中删除空白单元格并将填充的单元格向上移动

发布于 2025-01-19 06:23:06 字数 332 浏览 3 评论 0原文

我有这个 Excel 文件,我想删除 A 列中的所有空白单元格,并使用 python 将填充的单元格向上移动。

不知道该怎么做,有什么建议吗?我知道我可以进入 Excel 并手动执行此操作,但我需要自动化此过程。将创建多个与此类似的文件,我需要自动调整此设置,以便 A 列中的所有填充单元格实际上位于 B、C、D、E 中其余数据的旁边。

在此处输入图像描述

I have this excel file and I would like to delete all blank cells in columns A and shift the populated cells up using python.

Not sure how to do this, any advice? I know I can go into excel and do it manually but I need to automate this process. Multiple files looking just like this will be created, and I need to automate adjusting this so that all those populated cells in column A actually sit next to the rest of the data in B, C, D, E.

enter image description here

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

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

发布评论

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

评论(1

饮湿 2025-01-26 06:23:06

使用 pandas 导入和修改您的 Excel。

import pandas as pd
df = pd.read_excel('yourfile.xlsx')
df = df.apply(lambda x: pd.Series(x.dropna().values)).fillna(' ')

Use pandas to import and modify your excel.

import pandas as pd
df = pd.read_excel('yourfile.xlsx')
df = df.apply(lambda x: pd.Series(x.dropna().values)).fillna(' ')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文