原excel:
目标将year和month合并:
year、month里放的1961等是数字,合并日期的时候需要把它们变成字符串再合并,采用.astype(str)
#!usr/bin/env python # -*- coding:utf-8 -*- """ @author: Su @file: ceshi.py @time: 2023/06/26 @desc: """ import pandas as pd # 打开excel文件 df = pd.read_excel('G:/drought/processdata/lianxi/鄂尔多斯.xlsx') # 合并日期 df['date'] = df['year'].astype(str) + '-' + df['month'].astype(str) print(df['date'])
所得结果:
标签:python,合并,excel,astype,month,df,year,两列 From: https://www.cnblogs.com/shirleysu90/p/17564679.html