Created
April 16, 2011 20:30
-
-
Save snosrap/923468 to your computer and use it in GitHub Desktop.
Takes a CSV through STDIN and outputs a corresponding Entity-Attribute-Value (EAV) CSV on STDOUT
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
#!/usr/bin/python | |
import sys, csv | |
def main(): | |
csvIn = csv.reader(sys.stdin, delimiter=',', quotechar='"') | |
csvOut = csv.writer(sys.stdout) | |
for rowNum, row in enumerate(csvIn): | |
if rowNum == 0: | |
headers = row | |
else: | |
for columnNum, cell in enumerate(row): | |
if columnNum == 0: | |
entity = cell | |
elif cell: | |
csvOut.writerow([entity, headers[columnNum], cell]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment