Skip to content

Commit 061975b

Browse files
author
Sebastian Raschka
committed
reorganized Readme
1 parent 31a40c2 commit 061975b

2 files changed

Lines changed: 124 additions & 13 deletions

File tree

README.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,33 @@ Python Tutorials and References
44
Useful functions, tutorials, and other Python-related things
55

66

7-
###Links to view the IPython Notebooks
8-
9-
- [Python benchmarks via `timeit`](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/timeit_tests.ipynb?create=1)
10-
- [Implementing the least squares fit method for linear regression and speeding it up via Cython](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/cython_least_squares.ipynb?create=1)
11-
- [Benchmarks of different palindrome functions](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/palindrome_timeit.ipynb?create=1)
12-
- [A collection of not so obvious Python stuff you should know!](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/not_so_obvious_python_stuff.ipynb?create=1)
13-
- [Python's scope resolution for variable names and the LEGB rule](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/scope_resolution_legb_rule.ipynb?create=1)
14-
- [Happy Mother's Day](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/funstuff/happy_mothers_day.ipynb?create=1)
15-
16-
### Links to Markdown files
17-
- [A thorough guide to SQLite database operations in Python](./sqlite3_howto/README.md)
18-
- [Unit testing in Python - Why we want to make it a habit](./tutorials/unit_testing.md)
19-
- [Installing Scientific Packages for Python3 on MacOS 10.9 Mavericks](./tutorials/installing_scientific_packages.md)
7+
###Links to view the IPython Notebooks and Markdown files
8+
9+
<br>
10+
<br>
11+
<br>
12+
13+
**// Python tips and tutorials**
14+
15+
- A collection of not so obvious Python stuff you should know! [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/not_so_obvious_python_stuff.ipynb?create=1)
16+
- Python's scope resolution for variable names and the LEGB rule [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/scope_resolution_legb_rule.ipynb?create=1)
17+
- A thorough guide to SQLite database operations in Python [[Markdown]](./sqlite3_howto/README.md)
18+
- Unit testing in Python - Why we want to make it a habit [[Markdown]](./tutorials/unit_testing.md)
19+
- Installing Scientific Packages for Python3 on MacOS 10.9 Mavericks [[Markdown]](./tutorials/installing_scientific_packages.md)
20+
21+
**// benchmarks**
22+
23+
- Python benchmarks via `timeit` [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/timeit_tests.ipynb?create=1)
24+
- Implementing the least squares fit method for linear regression and speeding it up via Cython [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/cython_least_squares.ipynb?create=1)
25+
- Benchmarks of different palindrome functions [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/benchmarks/palindrome_timeit.ipynb?create=1)
26+
27+
28+
29+
**// other**
30+
31+
- Happy Mother's Day [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/funstuff/happy_mothers_day.ipynb?create=1)
32+
33+
34+
**// useful snippets**
35+
36+
- convert 'tab-delimited' to 'comma-separated' CSV files [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/useful_scripts/fix_tab_csv.ipynb?create=1)

useful_scripts/fix_tab_csv.ipynb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:996358a25da6fc77c66d183e79209307af06bd2f9abb0656d3bb70cfc2fe597a"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"Sebastian Raschka 05/09/2014"
16+
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"# Fixing CSV files"
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"metadata": {},
28+
"source": [
29+
"We have a directory `../CSV_files_raw/` with CSV files where some of them have 'tab-separated' and some of them 'comma-separated' columns. \n",
30+
"Here, we will 'fix' them, i.e., have them all comma-separated, and save them to a new directory `../CSV_fixed`."
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"First, we create a dictionary with the file basenames as keys. The values are lists of the file paths to the raw and new fixed CSV files. e.g., \n",
38+
"\n",
39+
" {\n",
40+
" 'abc.csv': ['../CSV_files_raw/abc.csv', '../CSV_fixed/abc.csv'], \n",
41+
" 'def.csv': ['../CSV_files_raw/def.csv', '../CSV_fixed/def.csv'], \n",
42+
" ...\n",
43+
" }"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"collapsed": false,
49+
"input": [
50+
"import sys\n",
51+
"import os\n",
52+
"\n",
53+
"raw_dir = '../CSV_files_raw/'\n",
54+
"fixed_dir = '../CSV_fixed'\n",
55+
"\n",
56+
"if not os.path.exists(fixed_dir):\n",
57+
" os.mkdir(fixed_dir)\n",
58+
"\n",
59+
"f_dict = {os.path.basename(f):[os.path.join(raw_dir, f),\n",
60+
" os.path.join(fixed_dir, f)]\n",
61+
" for f in os.listdir(raw_dir) if f.endswith('.csv')} "
62+
],
63+
"language": "python",
64+
"metadata": {},
65+
"outputs": [],
66+
"prompt_number": 8
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Now, we can replace the tabs with commas for the new files very easily:"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"collapsed": false,
78+
"input": [
79+
"for f in f_dict.keys():\n",
80+
" with open(f_dict[f][0], 'r') as raw, open(f_dict[f][1], 'w') as fixed:\n",
81+
" for line in raw:\n",
82+
" line = line.strip().split('\\t')\n",
83+
" fixed.write(','.join(line) + '\\n')"
84+
],
85+
"language": "python",
86+
"metadata": {},
87+
"outputs": [],
88+
"prompt_number": 11
89+
}
90+
],
91+
"metadata": {}
92+
}
93+
]
94+
}

0 commit comments

Comments
 (0)