gina.L
gina.L

Reputation: 71

DataFrame' object has no attribute 'sort'

hello~could u help me to solve the questions?

【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() 

the above codes are normal,but if I add the sentence below,python warns“'DataFrame' object has no attribute 'sort'”

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

Upvotes: 4

Views: 10045

Answers (1)

gina.L
gina.L

Reputation: 71

...Question solved.

The last code should be "counts_.sort_values('num',ascending=False)" instead.

Upvotes: 3

Related Questions