python-First Glimpse data analysis (including drawing)

Source: Internet
Author: User
Tags install matplotlib

Learn the previous crawler, today, using Python's matplotlib library to combine crawler crawling data to do a simple data analysis

                                 

(Install matplotlib(pip install matplotlib)before the second.)

  1. 1 #Lead Storage2 ImportPymongo3 ImportMatplotlib.pyplot as MP4 ImportRe5 #Connect to MongoDB6Client = Pymongo. Mongoclient ('mongodb://localhost:27017')7 #input value of reference value8Year = str (input ("Please enter the year: \ n"))9year2 = str (Input ("comparison year: \ n"))Ten #use fuzzy query year Ones = List (client['Houseprice']['CQ'].find ({'DateTime': Re.compile (Year)})) Aw = List (client['Houseprice']['CQ'].find ({'DateTime': Re.compile (YEAR2)})) - #defines four arrays for easy loading of data later -DT = [] thePrice = [] -DT2 = [] -Price2 = [] - #traversal adds time and price to the array +  forIinchS: -Dt.append (i["DateTime"][5:8]) +Price.append (int (i["Houseprice"][0:4])) A  forIinchW: atDt2.append (i["DateTime"][5:8]) -Price2.append (int (i["Houseprice"][0:4])) - #Table name -Mp.title ('Cqspbhouseprice') - #X-Axis notes -Mp.xlabel ('Month') in #Y-Axis notes -Mp.ylabel (' Price') to #Drawing Graphs +Mp.plot (DT, Price, label="Year :"+Year ) -Mp.plot (DT2, Price2, label="Year :"+year2) the #tip marker line and position distance *Mp.legend (bbox_to_anchor=[0.8, 1]) $ #grid linesPanax Notoginseng Mp.grid () - #Save the resulting picture theMp.savefig ('e:\practice\cqhouseprice\static\img/'+ year +'. PNG', dpi = 100) + #show the resulting picture A mp.show () the #Close +Mp.close ()

    Input:

Output

data analysis draw here, next chapter python with flask Match front-end Web presentation data

If there is a mistake, the shortcomings of the comments remind you

Thank you!

python-First Glimpse data analysis (including drawing)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.