pandas处理整列表格数据

img
如图所示怀孕天数已经算出,根据末次月经日期加上怀孕天数计算出生日期
注意:年月日要分开,数据较多要批量处理

pandas读取方法很多,

日期相加如下:


import datetime

t_str = '2017-07-27'
days = 159
last_d = datetime.datetime.strptime(t_str, '%Y-%m-%d')
delta = datetime.timedelta(days=days)
birth_day = last_d + delta
year, month, day = birth_day.year, birth_day.month, birth_day.day

print('末次月经:', t_str, '怀孕天数:', days)
print(birth_day.strftime('%Y-%m-%d'))
print('出生年月日:', year, month, day)

img