[英]How to copy and paste the previous value to next empty cell in Excel?
I have excel file我有excel文件
| Name | City | Start Date | |Alex | Hong Kong | 2021-02-01 | |Annie | Hong Kong | | |Bob | Taipei | | |Lucy | Tokyo | | |David | London | 2021-07-01 | |Kate | New York | | |Cathrine | London | | |Rose | Hong Kong | | |Mary | Hong Kong | 2021-09-01 | |Johnny | London | | |Roy | Taipei | |
I want to use python auto update the start date in empty cell like as below result.我想使用 python 自动更新空单元格中的开始日期,如下所示。
| Name | City | Start Date | |Alex | Hong Kong | 2021-02-01 | |Annie | Hong Kong | 2021-02-01 | |Bob | Taipei | 2021-02-01 | |Lucy | Tokyo | 2021-02-01 | |David | London | 2021-07-01 | |Kate | New York | 2021-07-01 | |Cathrine | London | 2021-07-01 | |Rose | Hong Kong | 2021-07-01 | |Mary | Hong Kong | 2021-09-01 | |Johnny | London | 2021-09-01 | |Roy | Taipei | 2021-09-01 |
I use openpyxl
read excel file我用
openpyxl
读取excel文件
df = pd.read_excel('C:/Users/Data.xlsx')
How to copy and paste the previous start date value to next empty cell?如何将上一个开始日期值复制并粘贴到下一个空单元格?
col = df['Start Date'] = np.where(df['Start Date'].isnull())
You can do it like this:你可以这样做:
for i, d in enumerate(df['Start Date']):
if d.strip() == '':
df.at[i,'Start Date'] = df.at[i-1,'Start Date']
Assuming your date fields are string.假设您的日期字段是字符串。 You probably have to adjust to your exact formatting.
您可能必须调整到您的确切格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.