Code to parse date and value

This is the place for queries that don't fit in any of the other categories.

Code to parse date and value

Postby joopiter » Mon Sep 26, 2016 1:38 pm

Hi there -- I'm entirely new to Python and want to learn. Part of my learning process is to write a script that can read my credit card bills in .csv format and produce data on it over a period of time -- e.g. how much I spend on Uber monthly.

So, I've been told that Pandas is an efficient way to do that. I'm using iPython, Python 3.0 to code this.

My .csv file (aug2016.csv) has many rows that are written in this format:

08 AUG UBER SG AUG09 JI3LA HELP.help.uber.comNL 000 16.00

As a start, I am looking to do the following:
i. Set the first two digits as the date for a month
ii. Set the second string of characters (i.e. AUG) as the month
iii. Take out "2016" from the file name "aug2016.csv" to set it as the year
iv. Take out the last string of digits - i.e. "16.00" and set that as the value
v. Search for keywords in the row -- for example, if there is any phrase that says 'UBER', I will classify the item as 'Transport'. If the sentence contains no recognized phrase, it puts it in a bucket called 'Other'.

Thoughts on how I can get started? Or best way to learn the ropes?

So far, all I've done is managed to read the .csv file into a data frame :) Slow, but I will get there...
Last edited by micseydel on Mon Sep 26, 2016 2:41 pm, edited 1 time in total.
Reason: Initial post lock.
joopiter
 
Posts: 1
Joined: Mon Sep 26, 2016 1:31 pm

Re: Code to parse date and value

Postby Ofnuts » Tue Sep 27, 2016 4:35 pm

pandas may be an overkill for this, the standard csv module is likely enough. With it each line is parsed into a list:

Code: Select all
['08', 'AUG', 'UBER', 'SG', 'AUG09', 'JI3LA', 'HELP.help.uber.comNL', '000', 16.00]


so you can access items using plain indexation.
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests