CSV  JSON  Python. 18   Pandas
 


 -   CSV, JSON  JSON Lines  Python  Pandas   .  18  :  , DictReader,  , , , ,  JSON,  CSVJSON, ,  ,     .      ,       .





 

CSV  JSON  Python. 18   Pandas





  





   


   ,       Python      :  ,  , JSON-      JSON Lines.

   Pandas,     .   :   ,   , , ,     csv  json.

      , ,  ,     .     ,   .




   


       :  , ,     .       .

    ,   :   ,  ,     .        .

      Python.    ,          .




  


1.    CSV- (#task-1)

2.     (#task-2)

3.     (#task-3)

4.   (#litres_trial_promo)

5.     (#litres_trial_promo)

6.  -3    (#litres_trial_promo)

7.      (#litres_trial_promo)

8.  JSON-  (#litres_trial_promo)

9.     JSON (#litres_trial_promo)

10.  JSON Lines (#litres_trial_promo)

11.  CSV  JSON (#litres_trial_promo)

12.  JSON  CSV (#litres_trial_promo)

13.     (#litres_trial_promo)

14.    email (#litres_trial_promo)

15.     (#litres_trial_promo)

16.      (#litres_trial_promo)

17.    (#litres_trial_promo)

18.     CSV  JSON (#litres_trial_promo)




 





 1.    CSV-



 

  : ,   .    ,     .




import csv, io



data = '''order_id,client,total

1001,,1290

1002,,870

1003,,410

'''



reader = csv.DictReader(io.StringIO(data))

result = sum(int(row['total']) for row in reader)


 

2570


 

io.StringIO    ,   .

DictReader         .

    int:  CSV    .


  

           TypeError  .


 

    330    .

:    1004,,330,   2900.




 2.    



 

   .       paid    .




import csv, io



data = '''order_id,status,total

2001,paid,700

2002,cancelled,500

2003,paid,1250

2004,new,900

'''



reader = csv.DictReader(io.StringIO(data))

result = [row['order_id'] for row in reader if row['status'] == 'paid']


 

['2001', '2003']


 

        .

   :     .

 ,   DictReader   .


  

      :          .


 

   2004  paid.    ?

:   ['2001', '2003', '2004'].




 3.    



 

     .     ' ',    .




import csv, io



data = '''client,city

,

,

,

'''



reader = csv.DictReader(io.StringIO(data))

result = []

for row in reader:

city = row['city'].strip() or ' '

result.append((row['client'], city))


 

[('', ''), ('', ' '), ('', '')]


 

strip    .

     .

      ,      .




  .


   .

   ,     (https://www.litres.ru/book/raznoe/csv-i-json-v-python-18-zadach-bez-pandas-74418613/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


