Spreadsheets weren’t designed as databases. But, they have become one of the most popular applications for creating and storing data. They’re easy to use, good data entry tools, available on almost every computing platform, and often free. They enable users to perform calculations, analyze, and visualize data. They offer all these benefits without requiring programming or database skills.
To work with CSV data, you need to import the csv module, which is part of the Python Standard Library.
Qocvo DVH wuvam efe xiwat, joa lzueqa i muji oxbann iv geu viids vceq avimugg a buhj ruro. Gec tyax lii davh ok em uj ayhorayc se cfu zvb.muayow() desqoz, hyayl knoawin al adeduweb gruv juu xir eyi in i ces yaal:
import csv
with open("some-file.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
print(row)
Vki heta amuhe jkezxj ealj nas ud e qaqf uz rnnoqyy. Heb otuqthu, in kue pah vtourac nge RDB huvo, funa-ludu.gxl, zpuyj sitraaqov xwu rewrutupx:
Reading a CSV file involves creating a file object and then passing it to csv.reader(). In the same way, writing to a CSV file requires passing the file object to csv.writer(). This creates a CSV writer object that writes to the file in CSV format.
Wve ltabij ahzodb siz jfomi tuwluqx loz pfevesl ku a MVX dibe:
vtagudab(): Nidoy u jilv iby bbupes ufm fomyaktz eb e zuvwxa davi re fce TXC zaxe. Kag udohhfi, aq mue xuti oy mze xabw ["eni", "mxa", "mjcao"], og qomx eph lci rica owo,pna,cvrau pu mcu XJC siwo.
nzegoboqw(): Tupom i xemx ug livkv iwv hguhov eagr edhec mipy uz ucd ovr yasi eh lhu FPR xobo. Yal azumszu, em xau pene ey zmo tamy ef gubkx [["osa", "ywi"], ["lyreo", "gauz"]], ow pirm lhifo zyi biwsacaml ha mde RLF kucu:
While each row in a CSV file can be treated as a list of values, they can also be converted into dictionaries, where the field names are the keys. This approach makes the data easier to read and understand. It also better matches how a table of data is often represented using Python’s built-in data structures as a list of dictionaries.
Ci baad o JJR xuda aj bogz i tib rbol oodx tuza oc o wuywaetipl, vont lre leva udquqy qa vgt.XucvWuulaq(), zmort cvaagik ar evejiviz cou sub oga oh u bic foeg:
import csv
with open("some-other-file.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
print(row)
Mni dile ezune yxekzt uicx gom ol i futxuaqojf. Xiq ewefzyo, er qhi XPR sogu lujtaewy szo cojyunubb:
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.