[Python] How to avoid adding time to date in Pandas to Excel

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    So I have excel file with data where some headers are text and over are dates like 19.07.2023 etc:

    Item/Date 19.07.2023 20.07.2023 21.07.2023
    Some Item 58 51 57


    When I importing this file to pandas it's looks like this: [​IMG]

    After that I just do some merging with over excel file to get new column with latest date and exporting back to excel and my date of 19.07.2023 is 2023-07-19 0:00:00 now. How to avoid adding not needed time and also avoid changing format to d-m-Y? A can specify in excel after that this is Date and format will be changet to corrct one, but I want to avoid additional steps in the process.

    [​IMG]

    Code example

    import pandas as pd
    test_df = pd.read_excel('file.xlsx')
    test2_df = pd.read_excel('file2.xlsb')
    test_total = test_df.merge(test2_df, how='outer').fillna(0)
    test_total.to_excel('file_total.xlsx', index = False)

    Continue reading...

Compartilhe esta Página