问题是酱紫的
现在有一个如下包含1900-2100这201年间每天的日期信息字典列表:
[{'year': 1901, 'month': 1, 'day': 1, 'lunar_year': 1900, 'lunar_month': 11, 'lunar_leap': False, 'lunar_day': 11}, {'year': 1901, 'month': 1, 'day': 2, 'lunar_year': 1900, 'lunar_month': 11, 'lunar_leap': False, 'lunar_day': 12},...........{'year': 2100, 'month': 12, 'day': 31, 'lunar_year': 2100, 'lunar_leap': False, 'lunar_month': 12, 'lunar_day': 1}]
然后我打算按照如下规则转换成年度数据编码表:
一年的数据可用20位的二进制数表示
0001 1000 1000 1000 1000
- 中间的12位代表当年12个月的天数,0代表29天,1代表30天.
- 最右边的4位转换成十进制的数表示闰几月.
- 最左边的4位代表闰月的天数,0001代表30天,0000代表29天.
我参考的帖子的作者是用pandas进行编码的(不过他没有给出对应的代码),作者得到的结果如下:
CHINESEYEARCODE = [
19416,
19168, 42352, 21717, 53856, 55632, 91476, 22176, 39632,
21970, 19168, 42422, 42192, 53840, 119381, 46400, 54944,
44450, 38320, 84343, 18800, 42160, 46261, 27216, 27968,
109396, 11104, 38256, 21234, 18800, 25958, 54432, 59984,
92821, 23248, 11104, 100067, 37600, 116951, 51536, 54432,
120998, 46416, 22176, 107956, 9680, 37584, 53938, 43344,
46423, 27808, 46416, 86869, 19872, 42416, 83315, 21168,
43432, 59728, 27296, 44710, 43856, 19296, 43748, 42352,
21088, 62051, 55632, 23383, 22176, 38608, 19925, 19152,
42192, 54484, 53840, 54616, 46400, 46752, 103846, 38320,
18864, 43380, 42160, 45690, 27216, 27968, 44870, 43872,
38256, 19189, 18800, 25776, 29859, 59984, 27480, 23232,
43872, 38613, 37600, 51552, 55636, 54432, 55888, 30034,
22176, 43959, 9680, 37584, 51893, 43344, 46240, 47780,
44368, 21977, 19360, 42416, 86390, 21168, 43312, 31060,
27296, 44368, 23378, 19296, 42726, 42208, 53856, 60005,
54576, 23200, 30371, 38608, 19195, 19152, 42192, 118966,
53840, 54560, 56645, 46496, 22224, 21938, 18864, 42359,
42160, 43600, 111189, 27936, 44448, 84835, 37744, 18936,
18800, 25776, 92326, 59984, 27296, 108228, 43744, 37600,
53987, 51552, 54615, 54432, 55888, 23893, 22176, 42704,
21972, 21200, 43448, 43344, 46240, 46758, 44368, 21920,
43940, 42416, 21168, 45683, 26928, 29495, 27296, 44368,
84821, 19296, 42352, 21732, 53600, 59752, 54560, 55968,
92838, 22224, 19168, 43476, 41680, 53584, 62034, 54560
]
由于没找到合适的pandas教程,我直接用基础的python来编码,结果如下:
[19168, 42352, 21717, 53856, 55632, 91476, 22176, 39632, 21970, 19168, 42422, 42192, 53840, 119381, 46400, 54944, 44450, 38320, 84343, 18800, 42160, 46261, 27216, 27968, 109396, 11104, 38256, 21234, 18800, 25958, 54432, 59984, 92821, 23248, 11104, 100067, 37600, 116951, 51536, 54432, 120998, 46416, 22176, 107956, 9680, 37584, 53938, 43344, 46423, 27808, 46416, 86869, 19872, 42416, 83315, 21168, 43432, 59728, 27296, 44710, 43856, 19296, 43748, 42352, 21088, 62051, 55632, 23383, 22176, 38608, 19925, 19152, 42192, 54484, 53840, 54616, 46400, 46752, 103846, 38320, 18864, 43380, 42160, 45690, 27216, 27968, 44870, 43872, 38256, 19189, 18800, 25776, 29859, 59984, 27480, 23232, 43872, 38613, 37600, 51552, 55636, 54432, 55888, 30034, 22176, 43959, 9680, 37584, 51893, 43344, 46240, 47780, 44368, 21977, 19360, 42416, 86390, 21168, 43312, 31060, 27296, 44368, 23378, 19296, 42726, 42208, 53856, 60005, 54576, 23200, 30371, 38608, 19195, 19152, 42192, 118966, 53840, 54560, 56645, 46496, 22224, 21938, 18864, 42359, 42160, 43600, 111189, 27936, 44448, 84835, 37744, 18936, 18800, 25776, 92326, 59984, 27308, 108228, 43744, 37600, 53987, 51552, 55127, 54432, 55888, 23893, 22176, 42704, 21972, 21200, 43448, 43344, 46240, 111270, 44368, 21920, 48036, 42416, 21168, 45683, 26928, 29495, 27296, 44368, 84821, 19296, 42352, 21732, 53600, 125032, 54560, 55968, 92838, 22224, 19168, 47572, 41680, 53584]
除了作者自己加上去的第一个编码以及最后两个由于不好处理暂时被我忽略掉的编码以外,有六个编码我的结果和作者不同,并且经过核对作者是对的,情况如下:
年份 | 正确编码 | 我的编码 | 差值 | 正确编码二进制 | 错误编码二进制 |
---|---|---|---|---|---|
2057 | 27296 | 27308 | 12 | 0b 110 1010 1010 0000 | 0b 110 1010 1010 1100 |
2063 | 54615 | 55127 | 512 | 0b 1101 0101 0101 0111 | 0b 1101 0111 0101 0111 |
2074 | 46758 | 111270 | 64512 | 0b 1011 0110 1010 0110 | 0b 1 1011 0010 1010 0110 |
2077 | 43940 | 48036 | 4096 | 0b 1010 1011 1010 0100 | 0b 1011 1011 1010 0100 |
2090 | 59752 | 125032 | 65280 | 0b 1110 1001 0110 1000 | 0b 1 1110 1000 0110 1000 |
2096 | 43476 | 47572 | 4096 | 0b 1010 1001 1101 0100 | 0b 1011 1001 1101 0100 |
这个Bug有点迷~
相关链接
参考文章
项目地址
ps:可以先看看项目的readme的关于开发这段