Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do in Python
#6
(May-24-2018, 03:53 PM)oldcity Wrote: The plan is to work with 11 categories.
If you want do some work with data Pandas give a lot for free,take a look later.
Can first look at csv module,i guss you want to add header so it look like this.
Output:
pdate,catg,atm,howp 010118,1,1.00,1 020218,2,2.22,2 030318,3,33.33,3 040418,4,44.44,4
This code gives output over.
import csv

with open("expenses-18.csv") as f, open("output.csv","w", newline='') as f_out:
    cr = csv.reader(f)
    cw = csv.writer(f_out)
    header = ['pdate', 'catg', 'atm', 'howp']
    cw.writerow(header)
    cw.writerows(cr)
Pandas as mention you get a lot for free ,if need to work with data.
Here add header,and all data get convert to integer64 or float64.
Now it's easy to calculate with data or add plot ect.
>>> import pandas

>>> df = pandas.read_csv('expenses-18.csv', header=None)
>>> df.columns = ['pdate', 'catg', 'atm', 'howp']

# It's now a Dataframe
>>> df
   pdate  catg    atm  howp
0  10118     1   1.00     1
1  20218     2   2.22     2
2  30318     3  33.33     3
3  40418     4  44.44     4

>>> # All is correct type
>>> df.catg
0    1
1    2
2    3
3    4
Name: catg, dtype: int64

>>> df.atm
0     1.00
1     2.22
2    33.33
3    44.44
Name: atm, dtype: float64
Quote:Using Python version 2.7.12 on Linux Mint 18.2.
Drop Python 2 there is no excuses for use it anymore Wink
Mint 18.2 comes with Python 3.5,look at Linux Python 3 environment
Reply


Messages In This Thread
How to do in Python - by oldcity - Apr-26-2018, 03:20 PM
RE: How to do in Python - by nilamo - Apr-26-2018, 03:45 PM
RE: How to do in Python - by oldcity - Apr-27-2018, 03:07 PM
RE: How to do in Python - by nilamo - Apr-27-2018, 03:22 PM
RE: How to do in Python - by oldcity - May-24-2018, 03:53 PM
RE: How to do in Python - by snippsat - May-24-2018, 06:22 PM
RE: How to do in Python - by nilamo - May-24-2018, 06:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020