《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()
這樣以後就可以了: