4

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)

1 Answer 1

3

...Question solved.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.