据帧'对象没有属性' sort'

时间:2017-06-14 10:45:48

标签: python-3.x anaconda

你好〜你可以帮我解决问题吗?

【Anaconda3-4.4.0】

import pandas as pd
from sqlalchemy import create_engine

engine = create_engine('mysql+pymysql://root:123456@localhost:3306/mysql?charset=utf8')
sql = pd.read_sql('all_gzdata', engine, chunksize = 10000)

counts = [ i['fullURLId'].value_counts() for i in sql] 
counts = pd.concat(counts).groupby(level=0).sum() 
counts = counts.reset_index() 
counts.columns = ['index', 'num'] 
counts['type'] = counts['index'].str.extract('(\d{3})') 
counts_ = counts[['type', 'num']].groupby('type').sum() 

以上代码是正常的,但如果我添加下面的句子,python会警告“' DataFrame'对象没有属性'排序'“

counts_.sort('num', ascending = False)

1 个答案:

答案 0 :(得分:3)

......问题解决了。

最后一个代码应该是“counts_.sort_values('num',ascending = False)”