資源描述:
《python data analysis working with databases》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、WorkingwithDatabasesIfyouworkwithdata,soonerorlater,youwillcomeintocontactwithdatabases.Thischapterintroducesvariousdatabases(relationalandNoSQL)andrelatedAPIs.Arelationaldatabaseisadatabasethathasacollectionoftablescontainingdataorganizedbytherelationsbetweendataitems.Arelationshipcanbesetu
2、pbetweeneachrowinthetableandarowinanothertable.Arelationaldatabasedoesnotjustpertaintorelationshipsbetweentables;firstly,ithastodowiththerelationshipbetweencolumnsinsideatable(obviously,columnswithinatablehavetoberelated,forinstance,anamecolumnandanaddresscolumninacustomertable);secondly,itr
3、elatestoconnectionsbetweentables.NoSQL(NotOnlySQL)databasesareundergoingsubstantialgrowthinBigDataandwebapplications.NoSQLsystemsmayinfactpermitSQL-likequerylanguagestobeemployed.ThemainthemeofNoSQLdatabasesisallowingdatatobestoredinamoreflexiblemannerthantherelationalmodelpermits.Thismaymea
4、nnothavingadatabaseschemaoraflexibledatabaseschema.Ofcourse,theflexibilityandspeedmaycomeatapricesuchaslimitedsupportforconsistenttransactions.NoSQLdatabasescanstoredatausingadictionarystyle,inacolumn-orientedway,asdocuments,objects,graphs,tuples,oracombinationthereof.Thetopicsofthischaptera
5、relistedasfollows:?Lightweightaccesswithsqlite3?Accessingdatabasesfrompandas?InstallingandsettingupSQLAlchemy?PopulatingadatabasewithSQLAlchemy?QueryingthedatabasewithSQLAlchemy?PonyORM?Dataset—databasesforlazypeople?PyMongoandMongoDB?StoringdatainRedis?ApacheCassandraWorkingwithDatabasesLig
6、htweightaccesswithsqlite3SQLiteisaverypopularrelationaldatabase.It'sverylightweightandusedbymanyapplications,forinstance,webbrowserssuchasMozillaFirefox.Thesqlite3moduleinthestandardPythondistributioncanbeusedtoworkwithaSQLitedatabase.Withsqlite3,wecaneitherstorethedatabaseinafileorkeepitinR
7、AM.Forthisexample,wewilldothelatter.Importsqlite3asfollows:importsqlite3Aconnectiontothedatabaseisneededtoproceed.Ifwewantedtostorethedatabaseinafile,wewouldprovideafilename.Instead,dothefollowing:withsqlite3.connect(":memory:")ascon:Thewithstateme