Analysing chart data with Python: how rare are Tử Vi patterns?

Scanning every day from 1 January 1960 to 31 December 2019, all 12 hours a day, gives 262,980 charts: the rarest pattern of the Complete Book of Tử Vi Đẩu Số is Quân thần khánh hội, on just 306 charts, about 1 in 859. The most common is Khoa Quyền Lộc củng at 4.90%. This guide shows how to count it yourself with the Python library nhatnguyet.
How the scan works
- Every solar day from 1960 to 2019 (21,915 days), all 12 hours from Tý to Hợi: 262,980 charts.
- One gender. We tried male and female on 576 sample charts and the patterns came out identical, because these patterns only look at star positions.
- Each chart counts once for each pattern it has. The rates are calendar rates, every day and hour weighted equally, not by how many people were actually born.
Steps
- Install the library:
pip install nhatnguyet. - Loop over days with
datetimeand over 12 hours, callingtu_vi.lap_la_so_tu_vi. - Call
tu_vi.nhan_dien_cach_cucon each chart and count by pattern name. - Patterns from the Complete Book carry a
nhomkey: wealth (định phú), rank (định quý) or hardship (định bần tiện), after the book's three tables. Count by table as well. - Print the rates, sorted from rare to common.
from collections import Counter
from datetime import date, timedelta
from nhatnguyet import tu_vi
count = Counter() # charts carrying each pattern
table = {} # which table of the Complete Book a pattern belongs to
by_table = Counter()
total = 0
day = date(1960, 1, 1)
while day <= date(2019, 12, 31):
for hour in range(12): # 0 is the Tý hour, 11 the Hợi hour
chart = tu_vi.lap_la_so_tu_vi("", "Nam", day.day, day.month, day.year, hour)
found = {c["ten"]: c for c in tu_vi.nhan_dien_cach_cuc(chart)}
total += 1
for name, c in found.items():
count[name] += 1
table[name] = c.get("nhom", "")
for t in {c.get("nhom") for c in found.values()} - {None}:
by_table[t] += 1
day += timedelta(days=1)
print(f"Scanned {total:,} charts")
for t, n in by_table.most_common():
print(f" table {t:14} {n:7,} charts {n / total:6.2%}")
print("The five rarest patterns of the Complete Book:")
for name, n in sorted((x for x in count.items() if table[x[0]]), key=lambda x: x[1])[:5]:
print(f" {name:22} {n:5,} charts {n / total:6.3%} (about 1 in {round(total / n):,})")It takes a few minutes on a laptop:
Scanned 262,980 charts
table dinh-quy 51,718 charts 19.67%
table dinh-ban-tien 24,503 charts 9.32%
table dinh-phu 12,951 charts 4.92%
The five rarest patterns of the Complete Book:
Quân thần khánh hội 306 charts 0.116% (about 1 in 859)
Lưỡng trùng Hoa Cái 362 charts 0.138% (about 1 in 726)
Tài Lộc giáp Mã 537 charts 0.204% (about 1 in 490)
Quyền Lộc sinh phùng 1,184 charts 0.450% (about 1 in 222)
Nhật Nguyệt đồng lâm 1,335 charts 0.508% (about 1 in 197)
Results: which patterns are rare, which are common?
| table of the Complete Book | charts with at least one pattern | rate |
|---|---|---|
| Rank (định quý) | 51,718 | 19.67% |
| Hardship (định bần tiện) | 24,503 | 9.32% |
| Wealth (định phú) | 12,951 | 4.92% |

- Rarest: Quân thần khánh hội 0.116%, Lưỡng trùng Hoa Cái 0.138%, Tài Lộc giáp Mã 0.204%.
- Most common: Khoa Quyền Lộc củng 4.90%, Nhất sinh cô bần 4.04%, Toạ quý hướng quý 3.35%.
- All 24 patterns of the three tables appear at least 306 times in this scan.
How to read the numbers
- These are frequencies of a rule, not of fate. The numbers say how many charts carry a pattern under the school's star-placement rules; they say nothing about the life of the person with that chart. Tử Vi's rules have not been tested.
- "Rare" does not mean "good". Lưỡng trùng Hoa Cái belongs to the hardship table yet is rarer than almost every rank pattern.
- For rates among real people, weight each day by the number of births on it; day and hour birth records for Vietnam are not public.
Where to go next
- Use
la_so["cung"]instead ofnhan_dien_cach_cucto count where each star falls, or how many charts have no main star in the Life palace. - Scan Bát Tự with
bat_tu.lap_la_so_bat_tuand count ten gods or symbolic stars. - Compare with the pre-computed readings on the open data page.
The code is MIT. If you quote these numbers, credit "Data: Nhat Nguyet (nhatnguyet.org)" and describe the scan as above. The code repository is on the open source page; the classic patterns are drawn in Tử Vi chart patterns in diagrams.



