鉴于这一目标:
{
"script": "Georgian",
"id": 7,
"script_family": "European",
"direction": "LTR",
"num_languages": 11,
"type": "Alphabet",
"date": 500,
"Continent": ""
},
{
"script": "Armenian",
"id": 8,
"script_family": "European",
"direction": "RTL",
"num_languages": 1,
"type": "Alphabet",
"date": 500,
"Continent": ""
},
{
"script": "Tamil",
"id": 9,
"script_family": "Indic",
"direction": "LTR",
"num_languages": 6,
"type": "Syllabary",
"date": 800,
"Continent": ""
},
{
"script": "Tibetan",
"id": 10,
"script_family": "Central Asian",
"direction": "LTR",
"num_languages": 45,
"type": "Abugida",
"date": 800,
"Continent": ""
},
{
"script": "Khmer",
"id": 11,
"script_family": "Mainland Southeast Asian",
"direction": "LTR",
"num_languages": 3,
"type": "Abugida",
"date": 900,
"Continent": ""
},
我想创建一个如下所示的对象数组,其中按日期分组,并包含每个脚本系列在该日期出现的脚本数
data = [
{date: 500, European: 2}
{date: 800, Indic: 1, Central Asia: 1}
...
]
其中,有时一个数据可以有多个脚本族
我尝试了以下代码:
family = data.groupby(['date', 'script_family'])['script_family'].count()
但当我将其导出为csv时,我只得到“脚本族”的计数,尽管我希望在特定日期出现的每个脚本族都设置为脚本数
date script_family
-400 European 1
-300 East Asian 1
-200 Middle Eastern 1
-100 European 1
500 African 1
European 2
600 Middle Eastern 1
800 Central Asian 1
Indic 1
900 East Asian 1
European 1
Indic 3
Mainland Southeast Asian 1
1000 Indic 1
1100 Indic 2
Mainland Southeast Asian 1
1200 Indic 1
1300 Central Asian 1
Mainland Southeast Asian 1
...
适用于Python 2.7.18和3.9.1:
参考:
相关问题 更多 >
编程相关推荐