-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathreadcsv.py
More file actions
66 lines (55 loc) · 1.4 KB
/
readcsv.py
File metadata and controls
66 lines (55 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
READCSV - CSV Debugging Utility
Simple command-line utility for parsing and displaying CSV data in a readable
key-value format. Reads CSV from stdin and prints each row as key-value pairs.
This is a debugging tool for quickly inspecting CSV files without loading them
into pandas or Excel.
Usage
-----
cat data.csv | python readcsv.py
python readcsv.py < data.csv
Output Format
-------------
For each row after the header, prints:
column1_name : value1
column2_name : value2
...
Example
-------
Input CSV:
ticker,price,volume
AAPL,150.25,1000000
MSFT,300.50,800000
Output:
ticker : AAPL
price : 150.25
volume : 1000000
ticker : MSFT
price : 300.50
volume : 800000
Limitations
-----------
- Only handles comma-separated values
- No support for quoted fields with commas
- First row must be header
- Does not handle complex CSV edge cases
Notes
-----
This is a minimal utility script for quick data inspection during development.
For production CSV parsing, use pandas.read_csv() or the csv module.
"""
from __future__ import division, print_function
import sys
cnt = 0
keys = dict()
for line in sys.stdin:
if cnt == 0:
for item in line.split(","):
keys[cnt] = item
cnt += 1
else:
ii = 0
for item in line.split(","):
print("{} : {}".format(keys[ii], item))
ii += 1