简体   繁体   English

如何将前一个值复制并粘贴到 Excel 中的下一个空单元格?

[英]How to copy and paste the previous value to next empty cell in Excel?

  1. 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 | |
  2. 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 |
  3. I use openpyxl read excel file我用openpyxl读取excel文件

    df = pd.read_excel('C:/Users/Data.xlsx')
  4. 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.

相关问题 使用 python 将我们的 excel 值复制到下一个单元格 - copy our excel value to the next cell with python 如果 pandas dataframe 中的下一个单元格的值为 0,我如何保持上一个单元格的值? - how can I keep the value of previous cell if the next is 0 in pandas dataframe? 复制单元格值并粘贴到搜索框中 - Copy cell value and paste into search box 保留前一个单元格值并复制到下一个单元格 python pandas dataframe - Retain the previous cell value and copy over to next cells python pandas dataframe PostgreSQL的。 如何使用python将行中单元格的值复制并粘贴到同一个表中另一行的另一个单元格中 - Postgresql. How to copy the value of a cell in a row and paste it into another cell of another row in the same table using python pandas 复制单元格中上一列的值 - pandas copy value of previous column in cell 根据上一个/下一个像元值​​确定像元值 - Determining a cell value based on previous/next cell value(s) 如何复制csv内容并将其粘贴到Excel工作表? - How to copy csv contents and paste to Excel sheet? 在python中获取以前的Excel单元格的值 - Getting the value of a previous excel cell in python 在Python中的excel单元格中自动填充上一个值 - Automatically fill in the previous value in an excel cell in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM