728x90
반응형
안타깝게도 팬더 데이터 프레임을 엑셀 파일로 변환하고 만료 날짜를 설정하는 작업은 팬더만 사용하여 수행할 수 없습니다. 그러나 openpyxl과 같은 타사 라이브러리를 사용하여 Excel 파일의 셀 만료 날짜를 설정할 수 있습니다.
다음은 예입니다:
import pandas as pd
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# Create an Excel Workbook object
book = Workbook()
# Select the first sheet
writer = pd.ExcelWriter('example.xlsx', engine='openpyxl')
df.to_excel(writer, index=False, sheet_name='Sheet1')
# Select the sheet
sheet = writer.sheets['Sheet1']
# Set the expiration date for a cell
expiry_date = '2023-02-02'
cell = sheet.cell(row=2, column=3)
cell.value = expiry_date
cell.number_format = 'MM/DD/YYYY'
# Save the workbook
writer.save()
이 예에서는 만료 날짜를 2023-03-02로 설정하고 시트 1의 2열과 3열에 위치한 셀에서 MM/DD/YYY로 포맷합니다.
728x90
반응형
'파이썬' 카테고리의 다른 글
엑셀 행에 선택표기를 할 수 있는 방법중 마우스로 클릭시 선택표시되는 파이썬 코드 (0) | 2023.02.10 |
---|---|
파이썬으로 엑셀파일에 암호 걸어두기 (0) | 2023.02.10 |
데이터프레임에서 엑셀파일로 변환시 1행에 필터활성화시켜 저장하는 예제 (0) | 2023.02.10 |
데이터프레임에서 열 크기를 정하고 열 크기를 벗어나는 문자수가 있다면 행을 늘려 모든 문자를 나타낼 수 있는 코드 (0) | 2023.02.10 |
데이터프레임에서 열의 간격을 문자수에 맞춰 자동으로 맞춰주는 코드 (0) | 2023.02.10 |