TenkajinKB/count_families.py
2026-04-19 16:16:20 +08:00

29 lines
1.2 KiB
Python

#!/usr/bin/env python3
with open('01_Active_Projects/N01_植物帝国企划/owm植物学AVGIV总览.md', 'r', encoding='utf-8') as f:
content = f.read()
sections = content.split('## ')
for s in sections:
if s.startswith('科视角'):
lines = s.strip().split('\n')
all_families = []
for line in lines:
if line.startswith('|') and '---' not in line:
cols = [c.strip() for c in line.split('|')]
if len(cols) > 5:
order_name = cols[2].strip()
fam_raw = cols[4].strip()
if (order_name and order_name != 'nan' and '' in order_name
and fam_raw and fam_raw != 'nan'):
all_families.append((order_name, fam_raw[:60]))
print(f'Total family entries: {len(all_families)}')
from collections import Counter
order_counts = Counter(f[0] for f in all_families)
for order, count in sorted(order_counts.items(), key=lambda x: -x[1]):
print(f' {order:10s}: {count} families')
# Show all unique orders
unique_orders = list(dict.fromkeys(f[0] for f in all_families))
print(f'\nUnique orders: {len(unique_orders)}')
break