Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

八字立春算法下,输出多年的数据,发现年干或许存在异常,可按demo输出200年数据验证 #33

Open
ZD9503 opened this issue Apr 4, 2024 · 1 comment

Comments

@ZD9503
Copy link

ZD9503 commented Apr 4, 2024

如图所示,
截图_20240405075429

代码demo如下
`
import datetime
import cnlunar
import pandas as pd
import os

start_date = datetime.datetime(1901, 11, 6, 0, 0)
end_date = datetime.datetime(1903, 12, 10, 0, 0)
delta = datetime.timedelta(days=1)

calendar = []
while start_date <= end_date:
# a = cnlunar.Lunar(start_date, godType='8char') # 常规算法,即在正月初一切换年干生肖
a = cnlunar.Lunar(start_date, godType='8char', year8Char='beginningOfSpring') # 八字立春切换算法。

dic = {
    '公历日期': a.date,
    '农历日期数字': '%s-%s-%s' % (a.lunarYear, a.lunarMonth, a.lunarDay),
    '农历日期': '%s%s' % (a.lunarMonthCn, a.lunarDayCn),
    '星期': a.weekDayCn,
    '年干支': a.year8Char,
    '月干支': a.month8Char,
    '日干支': a.day8Char,
    # '时干支': a.twohour8Char,
    '今日节气': a.todaySolarTerms,
    '下一节气': (a.nextSolarTerm, a.nextSolarTermDate, a.nextSolarTermYear),
    '今年节气表': a.thisYearSolarTermsDic,
}
calendar.append(dic)
start_date += delta
print(start_date)

df = pd.DataFrame(calendar)
file_name = "万年历输出表.xlsx"

sheet_name = datetime.datetime.now().strftime("%H-%M-%S")
if os.path.exists(file_name):
# 如果文件已存在,读取原有数据
with pd.ExcelWriter(file_name, mode='a') as writer:
df.to_excel(writer, sheet_name=sheet_name, index=False)
print(f"已在 {file_name} 中添加新的sheet表:{sheet_name}")
else:
# 如果文件不存在,直接保存
df.to_excel(file_name, sheet_name=sheet_name, index=False)
print(f"已在 {file_name} 中创建新的sheet表:{sheet_name}")
`

@cuba3
Copy link
Member

cuba3 commented Apr 11, 2024

如图所示, 截图_20240405075429

代码demo如下 ` import datetime import cnlunar import pandas as pd import os

start_date = datetime.datetime(1901, 11, 6, 0, 0) end_date = datetime.datetime(1903, 12, 10, 0, 0) delta = datetime.timedelta(days=1)

calendar = [] while start_date <= end_date: # a = cnlunar.Lunar(start_date, godType='8char') # 常规算法,即在正月初一切换年干生肖 a = cnlunar.Lunar(start_date, godType='8char', year8Char='beginningOfSpring') # 八字立春切换算法。

dic = {
    '公历日期': a.date,
    '农历日期数字': '%s-%s-%s' % (a.lunarYear, a.lunarMonth, a.lunarDay),
    '农历日期': '%s%s' % (a.lunarMonthCn, a.lunarDayCn),
    '星期': a.weekDayCn,
    '年干支': a.year8Char,
    '月干支': a.month8Char,
    '日干支': a.day8Char,
    # '时干支': a.twohour8Char,
    '今日节气': a.todaySolarTerms,
    '下一节气': (a.nextSolarTerm, a.nextSolarTermDate, a.nextSolarTermYear),
    '今年节气表': a.thisYearSolarTermsDic,
}
calendar.append(dic)
start_date += delta
print(start_date)

df = pd.DataFrame(calendar) file_name = "万年历输出表.xlsx"

sheet_name = datetime.datetime.now().strftime("%H-%M-%S") if os.path.exists(file_name): # 如果文件已存在,读取原有数据 with pd.ExcelWriter(file_name, mode='a') as writer: df.to_excel(writer, sheet_name=sheet_name, index=False) print(f"已在 {file_name} 中添加新的sheet表:{sheet_name}") else: # 如果文件不存在,直接保存 df.to_excel(file_name, sheet_name=sheet_name, index=False) print(f"已在 {file_name} 中创建新的sheet表:{sheet_name}") `

我已经预料到这个问题了,如果采用常规算法a = cnlunar.Lunar(start_date, godType='8char') # 常规算法,应该是没问题,立春切年柱这个算法目前没有任何书籍支持,是之前一个网友让我加进来的,本质上和《钦定协纪辨方书》的逻辑是相违背的,我看一下算法问题在哪修一下吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants