{ "info": { "author": "metagriffin", "author_email": "metagriffin@uberdev.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "======\ncsvmod\n======\n\nA stream-oriented CSV modification tool. Like a stripped-down \"sed\"\ncommand, but for tabular data.\n\n\nTL;DR\n=====\n\nInstall:\n\n.. code-block:: bash\n\n $ pip install csvsed\n\nUse:\n\n.. code-block:: bash\n\n # given a sample CSV\n $ cat sample.csv\n\n Employee ID,Age,Wage,Status\n 8783,47,\"104,343,873.83\",\"All good, but nowhere to go.\"\n 2003,32,\"98,878,784.00\",A-OK\n\n # modify that data with a series of `csvsed` pipes\n $ cat sample.csv \\\n | csvsed -c Wage s/,//g \\ # remove commas from the Wage column\n | csvsed -c Status 'y/A-Z/a-z/' \\ # convert Status to all lowercase\n | csvsed -c Status 's/.*(ok|good).*/\\1/' \\ # restrict to keywords 'ok' & 'good'\n | csvsed -c Age 'e/xargs -I {} echo \"{}*2\" | bc/' # double the Age column\n\n Employee ID,Age,Wage,Status\n 8783,94,104343873.83,good\n 2003,64,98878784.00,ok\n\n\nInstallation\n============\n\n.. code-block:: bash\n\n $ pip install csvsed\n\n\nUsage and Examples\n==================\n\nInstallation of the `csvsed` python package also installs the\n``csvsed`` command-line tool. Use ``csvsed --help`` for all command\nline options, but here are some examples to get you going. Given the\ninput file ``sample.csv``:\n\n.. code-block:: text\n\n Employee ID,Age,Wage,Status\n 8783,47,\"104,343,873.83\",\"All good, but nowhere to go.\"\n 2003,32,\"98,878,784.00\",A-OK\n\nRemoving thousands-separators from the \"Wage\" column using the \"s\"\n(substitute) modifier:\n\n.. code-block:: bash\n\n $ cat sample.csv | csvsed -c Wage s/,//g\n Employee ID,Age,Wage,Status\n 8783,47,104343873.83,\"All good, but nowhere to go.\"\n 2003,32,98878784.00,A-OK\n\nConvert/extract some text using the \"s\" (substitute) and \"y\"\n(transliterate) modifiers:\n\n.. code-block:: bash\n\n $ cat sample.csv | csvsed -c Status 's/^All (.*),.*/\\1/' \\\n | csvsed -c Status 's/^A-(.*)/\\1/' \\\n | csvsed -c Status 'y/a-z/A-Z/'\n Employee ID,Age,Wage,Status\n 8783,47,\"104,343,873.83\",GOOD\n 2003,32,\"98,878,784.00\",OK\n\nSquare the \"Age\" column using the \"e\" (execute) modifier:\n\n.. code-block:: bash\n\n $ cat sample.csv | csvsed -c Age 'e/xargs -I {} echo \"{}^2\" | bc/'\n Employee ID,Age,Wage,Status\n 8783,2209,\"104,343,873.83\",\"All good, but nowhere to go.\"\n 2003,1024,\"98,878,784.00\",A-OK\n\nThat, however, called the external program for each column (quite\ninefficient with large data sets)... so let's do that more\nefficiently, with a \"continuous\" mode program. Given the following\n``id2name.py`` program which takes a CSV on STDIN with a single column\n(an employee ID) and writes a CSV to STDOUT with the IDs converted to\nnames:\n\n.. code-block:: python\n\n #!/usr/bin/env python\n import sys, csvkit\n table = {'8783': 'ElfenKyng', '2003': 'Stradivarius'}\n # NOTE: *not* using csvkit's reader because it reads-ahead\n # causing problems since this must be stream-oriented...\n writer = csvkit.CSVKitWriter(sys.stdout)\n while True:\n item = sys.stdin.readline()\n if not item: break\n item = item.strip()\n writer.writerow([table[item] if item in table else item])\n sys.stdout.flush()\n\nThen the following will efficiently convert the 'Employee ID' column\nto names:\n\n.. code-block:: bash\n\n $ cat sample.csv | csvsed -c 'Employee ID' 'e|./id2name.py|c'\n Employee ID,Age,Wage,Status\n ElfenKyng,47,\"104,343,873.83\",\"All good, but nowhere to go.\"\n Stradivarius,32,\"98,878,784.00\",A-OK", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/metagriffin/csvsed", "keywords": "CSV comma separated values modification substitution translation transliteration command-line library", "license": "GPLv3+", "maintainer": null, "maintainer_email": null, "name": "csvsed", "package_url": "https://pypi.org/project/csvsed/", "platform": "any", "project_url": "https://pypi.org/project/csvsed/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/metagriffin/csvsed" }, "release_url": "https://pypi.org/project/csvsed/0.2.4/", "requires_dist": null, "requires_python": null, "summary": "A stream-oriented CSV modification tool", "version": "0.2.4" }, "last_serial": 2014510, "releases": { "0.2.1": [ { "comment_text": "", "digests": { "md5": "89935446aa2ac83735521a438146e231", "sha256": "0dbcab20d3089b7f1dea7d001c2646d6f74b52e1bbd69e96e0b4ccdb9fda8884" }, "downloads": -1, "filename": "csvsed-0.2.1.tar.gz", "has_sig": false, "md5_digest": "89935446aa2ac83735521a438146e231", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5821, "upload_time": "2013-06-23T20:43:33", "url": "https://files.pythonhosted.org/packages/97/29/4006e9a90ea26b5333d91382f624950de85512a71bbff0afd872e7ed3551/csvsed-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "682fa77ba5968b3c8f5bd66aa9853207", "sha256": "9943c4c4de22ab91c15003a6ae8c61a5e884b22f7a08f30f6facadea84ab01d7" }, "downloads": -1, "filename": "csvsed-0.2.2.tar.gz", "has_sig": false, "md5_digest": "682fa77ba5968b3c8f5bd66aa9853207", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8133, "upload_time": "2013-09-04T21:14:07", "url": "https://files.pythonhosted.org/packages/c0/49/95e2583d989d6cc1a2b382595e3fe531769e1cbdbbc142c7809bc6769bfd/csvsed-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "735e654bb0aae812a76487c7d313aacd", "sha256": "c01043b31c6a4e68b1a74ed466a6ed442c296bfa6ab6ca58f90e25fc42f71933" }, "downloads": -1, "filename": "csvsed-0.2.3.tar.gz", "has_sig": false, "md5_digest": "735e654bb0aae812a76487c7d313aacd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8445, "upload_time": "2013-09-04T22:13:56", "url": "https://files.pythonhosted.org/packages/2c/d8/a8877a6ec2973a0afa8b3871d8edfc615a96f7c4e79cbe76c5dca7883d5f/csvsed-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "04c7c6b5a8625ae8ed8b36ab45211675", "sha256": "d5f68c9e2770990e3dba4af0dead31181c005db0cfe29e0efd2e1075a338c86a" }, "downloads": -1, "filename": "csvsed-0.2.4.tar.gz", "has_sig": false, "md5_digest": "04c7c6b5a8625ae8ed8b36ab45211675", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21012, "upload_time": "2016-03-18T15:15:31", "url": "https://files.pythonhosted.org/packages/04/f3/875e57e6c2fe2809d6e6071a31f884822e26a4db0998152a4c0e3dc94a16/csvsed-0.2.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "04c7c6b5a8625ae8ed8b36ab45211675", "sha256": "d5f68c9e2770990e3dba4af0dead31181c005db0cfe29e0efd2e1075a338c86a" }, "downloads": -1, "filename": "csvsed-0.2.4.tar.gz", "has_sig": false, "md5_digest": "04c7c6b5a8625ae8ed8b36ab45211675", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21012, "upload_time": "2016-03-18T15:15:31", "url": "https://files.pythonhosted.org/packages/04/f3/875e57e6c2fe2809d6e6071a31f884822e26a4db0998152a4c0e3dc94a16/csvsed-0.2.4.tar.gz" } ] }