[英]Automatically fill in the previous value in an excel cell in Python
我是 Python 的初学者。 我有一些excel问题。
1.我有excel文件。
| Name | Score |
|Alex | 83.5 |
|Annie | |
|Bob | |
|Lucy | 243.1 |
|David | |
|Kate | |
|Cathrine | |
|Rose | 757.5 |
|Mary | |
|Johnny | |
|Roy | |
我想让Score
自动填写以前分数的空单元格。 以下是我的预期结果。
| Name | Score | |Alex | 83.5 | |Annie | 83.5 | |Bob | 83.5 | |Lucy | 243.1 | |David | 243.1 | |Kate | 243.1 | |Cathrine | 243.1 | |Rose | 757.5 | |Mary | 757.5 | |Johnny | 757.5 | |Roy | 757.5 |
但是我的代码不起作用。 请教我如何编辑。
df = pd.read_excel('C:/Users/Data.xlsx') for i, j in enumerate(df['Score']): if j() == '': df.at[i,'Score'] = df.at[i-1,'Score']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.