Skip to content

Commit

Permalink
Merge pull request #338 from MattHJensen/pep8-ex-e402
Browse files Browse the repository at this point in the history
pep8-ex-e402 compliance
  • Loading branch information
talumbau committed Aug 11, 2015
2 parents 7879cb7 + 9590dd4 commit e5cbc0e
Show file tree
Hide file tree
Showing 23 changed files with 1,328 additions and 1,191 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ install:
- export PATH="$HOME/miniconda/bin:$PATH"
- conda config --set always_yes yes --set changeps1 no
- conda update conda
- conda create -n test-environment python=$TRAVIS_PYTHON_VERSION pytest numpy pandas
- conda install -n test-environment numba networkx six toolz
- source activate test-environment
- conda env create
- source activate taxcalc-dev
- python setup.py install


# command to run tests, e.g. python setup.py test
script:
- python -c "import taxcalc"; py.test
- python -c "import taxcalc"; py.test --pep8
42 changes: 24 additions & 18 deletions csv_to_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,50 @@
Turns csv output of tax calculator to ascii output with uniform columns
and transposes data so columns are rows, rows are columns
In ipython notebook, you can import this script as a module, and then use the function from the module.
In ipython notebook, you can import this script as a module, and then use the
function from the module.
"""

import pandas as pd


def ascii_output(csv_results="", ascii_results=""):

if csv_results == "":
print("no csv file given!")
exit(0)
if ascii_results == "":
print("no output file name given!")
exit(0)

#list of integers corresponding to the number(s) of the row(s) in the
#csv file, only rows in list will be recorded in final output
#if left as [], results in entire file being converted to ascii
#put in order from smallest to largest, for example:
#recids = [33180, 64023, 68020, 74700, 84723, 98001, 107039, 107298, 108820]
recids = [1,4,5]

#Number of characters in each column, must be whole nonnegative integer
# list of integers corresponding to the number(s) of the row(s) in the
# csv file, only rows in list will be recorded in final output
# if left as [], results in entire file being converted to ascii
# put in order from smallest to largest, for example:
# recids = [33180, 64023, 68020, 74700, 84723, 98001, 107039, 107298,
# 108820]
recids = [1, 4, 5]

# Number of characters in each column, must be whole nonnegative integer
col_size = 15

df = pd.read_csv(csv_results, dtype=object)
#keeps only listed recid's

# keeps only listed recid's
if recids != []:
f = lambda x : x - 1
recids = map(f, recids) #maps recids to correct index in df

def f(x):
return x - 1
recids = map(f, recids) # maps recids to correct index in df
df = df.ix[recids]

#does transposition
# does transposition
out = df.T.reset_index()

#formats data into uniform columns
# formats data into uniform columns
fstring = '{:' + str(col_size) + '}'
out = out.applymap(fstring.format)

out.to_csv(ascii_results, header=False, index=False, delim_whitespace=True, sep='\t')
out.to_csv(ascii_results, header=False, index=False,
delim_whitespace=True, sep='\t')
Loading

0 comments on commit e5cbc0e

Please sign in to comment.