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 #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)