First, read and write CSV data:
#!/usr/bin/env Python3#-*-Coding=utf8-*-ImportCsvwith Open ('Kxtx.csv','RT') as F:f_csv=CSV. Dictreader (f) forXinchf_csv:Print(x)ifx['Name of Goods'] =='Motor': Break
[Email protected] ~/py_script $ python3 csv_test.py {' Open single dot organization number ': ' C050220002 ', ' waybill number ': ' yt050806 ', ' Company type ': ' Project client ', ' first to undertake dot ' : ' Hou de Tianjin site ', ' affiliated hub ': ' Tianjin card line World Supply Chain Management Co., Ltd. ', ' Cargo name ': ' XM food ', ' Open a company ': ' XM Tianjin Mao Yi Express Logistics Co., Ltd. ', ' Number of pieces ': ' 500 ', ' the first to undertake the company type ': ' Line company ', ' ' XM Tianjin Mao Yi Express Logistics Co., Ltd. ', ' the first to undertake the company ': ' Binjiang Hou de logistics (Tianjin) Co., Ltd. ', ' Customer number ': ' k020220197 ', ' Consignment date ': ' 2016-05-08 ', ' outsourcing total (yuan) ': ' 9189.18 ', ' Billing date ': ' 2016-05-08 ', ' Volume (m3) ': ' 102 ', ' Weight (KG) ': ' 3562 ', ' transaction type ': ' Autonomous trading ', ' freight total (yuan) ': ' 9189.18 ', ' current status ': ' Customer has signed '} {' To open a single dot organization number ': ' C050 100014 ', ' waybill number ': ' C0501000140000615 ', ' Company type ': ' Project client ', ' first to undertake network ': ' Beijing land bridge Precision Beijing site ', ' affiliated hub ': ' Beijing card Line World Limited ', ' Cargo name ': ' Motor ', ' open a single company ': ' Beijing Heshun Tongda Logistics Co., Ltd. ', ' Number of pieces ': ' 43 ', ' first to undertake the company type ': ' Line company ', ' open a single dot ': ' Beijing Heshun Tongda Logistics Co., Ltd. ', ' the first to undertake the company ': ' Beijing Bridge Logistics Co., Ltd. (Precision) ', ' Customer number ': ' K020100048 ', ' Consignment date ': ' 2016-05-10 ', ' outsourced total (yuan) ': ' 1173.6 ', ' Billing date ': ' 2016-05-10 ', ' Volume (m3) ': ' 4.51 ', ' Weight (KG) ': ' 1956 ', ' Transaction type ': ' Autonomous trading ', ' shipped Fee Total (yuan) ': ' 1173.6 ', ' current status ': ' Customer has been signed '}
#!/usr/bin/env Python3#-*-Coding=utf8-*-Importcsvheaders= ['name','Age','Sex']rows= [('Zhang San', 27,'male'), ('John Doe', 24,'female')]with Open ('Testfile.csv','WT') as F:f_csv=Csv.writer (f) f_csv.writerow (headers) f_csv.writerows (rows)
[Email protected] ~/py_script $ cat testfile.csv name, age, Sex Zhang San, 27, male John Doe, 24, female
Ii. Data Aggregation and statistics: Pandas (large data set analysis, data grouping, statistical analysis, etc.)
>>> import pandas > >> test = pandas.read_csv ( " kxtx.csv " ) >>> test the date of shipment of the pivot to open a single company 0 Tianjin card Line World Supply Chain Management Co., Ltd. 2016-05-08 2016-05 -08 xm Tianjin Mao Yi Express Logistics Co., Ltd. 1 Beijing card Line World Limited 2016-05-10 2016-05-10 Beijing Heshun Tongda Logistics Co., Ltd. 2 Tianjin card line World Supply Chain Management Co., Ltd 2016-05-07 2016-05-07 xm Tianjin Mao Yi Express Logistics Co., Ltd. Division 3 Shijiazhuang Card line supply Chain Management Co., Ltd. 2016-05-07 2016-05-07 XM Hebei an Yue Trading Co., Ltd.
>>> type (test) <class ' Pandas.core.frame.DataFrame ' >
Python3 from zero--{initial consciousness: 006~ data encoding and processing}