《Python数据处理》9.1.6创建分组笔记:NameError:name text_type is not defined

《Python数据处理》9.1.6创建分组笔记:NameError:name text_type is not defined

一、现象

源码:

import json
from 数据集连接再测试 import cpi_and_cl
import pprint
import agate
path = 'I:\\360下载\\data-wrangling\\data\\chp9\\earth.json'

country_json = json.loads(open(path, 'r', encoding='utf-8').read())

country_dict = {}

for dct in country_json:
'''提取json形成单独对应的组'''
country_dict[dct['name']] = dct['parent']
#pprint.pprint(country_dict)

def get_country(country_row):
 '''获得大洲的名称'''
	return country_dict.get(country_row['Country / Territory'].lower())

#pprint.pprint(get_country())

#for r in cpi_and_cl().rows:
	#print(r['Country / Territory'],r['continent'])
#continent:大洲
#print(cpi_and_cl().columns[0])
cpi_and_cl = cpi_and_cl().compute([('continent', agate.Formula(text_type, get_country)),])

报错:

	NameError: name 'text_type' is not defined

在这里插入图片描述

二、解决方法

(一)查阅文档

链接: link.

但是文档中也是一样
在这里插入图片描述

(二)Github中的问题寻找

链接: link.
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
解决方法:

full_names = exonerations.compute([
('full_name', agate.Formula(agate.Text(), lambda row: '%(first_name)s %(last_name)s' % row))
])

将text_type改为agate.Text()

这样以后就可以了:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值