Last active
February 29, 2016 13:46
-
-
Save yilas/8ce55f7c9a84c4e785f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# csv | |
import csv | |
file_csv = '' | |
csvfile = open(file_csv, 'rb') | |
reader = csv.reader(csvfile) | |
for row in reader: | |
print row | |
import csv | |
file_csv = '' | |
csvfile = open(file_csv, 'rb') | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
print row | |
# json | |
import json | |
json_data = open('data-text.json').read() | |
data = json.loads(json_data) | |
for item in data: | |
print item | |
# XML Data | |
from xml.etree import ElementTree as ET | |
tree = ET.parse('data-text.xml') | |
root = tree.getroot() | |
data = root.find('Data') | |
all_data = [] | |
for observation in data: | |
record = {} | |
for item in observation: | |
lookup_key = item.attrib.keys()[0] | |
if lookup_key == 'Numeric': | |
rec_key = 'NUMERIC' | |
rec_value = item.attrib['Numeric'] | |
else: | |
rec_key = item.attrib[lookup_key] | |
rec_value = item.attrib['Code'] | |
record[rec_key] = rec_value | |
all_data.append(record) | |
print all_data | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment