quick-csv


Namequick-csv JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/dhchenx/quick-csv
SummaryRead and write CSV or TXT files in a simple manner
upload_time2022-08-30 09:58:17
maintainer
docs_urlNone
authorDonghua Chen
requires_python>=3.6, <4
licenseMIT
keywords csv file txt file write read quick-csv quickcsv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Quick CSV

Read and write small or large CSV/TXT files in a simple manner

### Installation
```pip
pip install quick-csv
```

### Examples for small files
Example 1: read and write csv or txt files
```python
from quickcsv.file import *
# read a csv file
list_model=read_csv('data/test.csv')
for idx,model in enumerate(list_model):
    print(model)
    list_model[idx]['id']=idx
# save a csv file
write_csv('data/test1.csv',list_model)

# write a text file
write_text('data/text1.txt',"Hello World!")
# read a text file
print(read_text('data/text1.txt'))
```
Example 2: create dataframe from a list of models
```python
from quickcsv.file import *
# read a csv file
list_model=read_csv('data/test.csv')
# create a dataframe from list_model
df=create_df(list_model)
# print
print(df)
```

### Examples for large files
Example 1: read large csv file
```python
from quickcsv.largefile import *
if __name__=="__main__":
    csv_path=r"umls_atui_rels.csv" # a large file (>500 MB)
    total_count=0

    def process_partition(part_df,i):
        print(f"Part {i}")

    def process_row(row,i):
        global total_count
        print(i)
        total_count+=1

    list_results=read_large_csv(csv_file=csv_path,row_func=process_row,partition_func=process_partition)

    print("Return: ")
    print(list_results)

    print("Total Record Num: ",total_count)

```

Example 2: query from a large csv file
```python
from quickcsv.largefile import *

if __name__=="__main__":
    csv_path=r"umls_sui_nodes.csv" # a large file (>500 MB)
    total_count=0
    # process each partition in the large file
    def process_partition(part_df,i):
        print(f"Part {i}")
        print()
    # process each row in a partition while reading
    def process_row(row,i):
        global total_count
        print(row)
        total_count+=1
    # field is a field in the csv file, and value is the value you need to find within the csv file
    list_results=read_large_csv(csv_file=csv_path, field="SUI",value="S0000004", append_row=True, row_func=process_row,partition_func=process_partition)

    print("Return: ")
    print(list_results)

    print("Total Record Num: ",total_count)
```

Example 3: read top N records from the large csv file
```python
from quickcsv.largefile import *

if __name__=="__main__":
    csv_path=r"umls_atui_rels.csv"
    total_count=0
    # return top 10 rows in the csv file
    list_results=read_large_csv(csv_file=csv_path,head_num=10)

    print("Return: ")
    print(list_results)

    print("Total Record Num: ",total_count)
```

### License

The `quick-csv` project is provided by [Donghua Chen](https://github.com/dhchenx). 




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dhchenx/quick-csv",
    "name": "quick-csv",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "csv file,txt file,write,read,quick-csv,quickcsv",
    "author": "Donghua Chen",
    "author_email": "douglaschan@126.com",
    "download_url": "https://files.pythonhosted.org/packages/ce/8c/b2c6ada29f6f37875cf558d3813e05b880af968f34ddc45b1b508c2d5ee6/quick-csv-0.0.5.tar.gz",
    "platform": null,
    "description": "## Quick CSV\n\nRead and write small or large CSV/TXT files in a simple manner\n\n### Installation\n```pip\npip install quick-csv\n```\n\n### Examples for small files\nExample 1: read and write csv or txt files\n```python\nfrom quickcsv.file import *\n# read a csv file\nlist_model=read_csv('data/test.csv')\nfor idx,model in enumerate(list_model):\n    print(model)\n    list_model[idx]['id']=idx\n# save a csv file\nwrite_csv('data/test1.csv',list_model)\n\n# write a text file\nwrite_text('data/text1.txt',\"Hello World!\")\n# read a text file\nprint(read_text('data/text1.txt'))\n```\nExample 2: create dataframe from a list of models\n```python\nfrom quickcsv.file import *\n# read a csv file\nlist_model=read_csv('data/test.csv')\n# create a dataframe from list_model\ndf=create_df(list_model)\n# print\nprint(df)\n```\n\n### Examples for large files\nExample 1: read large csv file\n```python\nfrom quickcsv.largefile import *\nif __name__==\"__main__\":\n    csv_path=r\"umls_atui_rels.csv\" # a large file (>500 MB)\n    total_count=0\n\n    def process_partition(part_df,i):\n        print(f\"Part {i}\")\n\n    def process_row(row,i):\n        global total_count\n        print(i)\n        total_count+=1\n\n    list_results=read_large_csv(csv_file=csv_path,row_func=process_row,partition_func=process_partition)\n\n    print(\"Return: \")\n    print(list_results)\n\n    print(\"Total Record Num: \",total_count)\n\n```\n\nExample 2: query from a large csv file\n```python\nfrom quickcsv.largefile import *\n\nif __name__==\"__main__\":\n    csv_path=r\"umls_sui_nodes.csv\" # a large file (>500 MB)\n    total_count=0\n    # process each partition in the large file\n    def process_partition(part_df,i):\n        print(f\"Part {i}\")\n        print()\n    # process each row in a partition while reading\n    def process_row(row,i):\n        global total_count\n        print(row)\n        total_count+=1\n    # field is a field in the csv file, and value is the value you need to find within the csv file\n    list_results=read_large_csv(csv_file=csv_path, field=\"SUI\",value=\"S0000004\", append_row=True, row_func=process_row,partition_func=process_partition)\n\n    print(\"Return: \")\n    print(list_results)\n\n    print(\"Total Record Num: \",total_count)\n```\n\nExample 3: read top N records from the large csv file\n```python\nfrom quickcsv.largefile import *\n\nif __name__==\"__main__\":\n    csv_path=r\"umls_atui_rels.csv\"\n    total_count=0\n    # return top 10 rows in the csv file\n    list_results=read_large_csv(csv_file=csv_path,head_num=10)\n\n    print(\"Return: \")\n    print(list_results)\n\n    print(\"Total Record Num: \",total_count)\n```\n\n### License\n\nThe `quick-csv` project is provided by [Donghua Chen](https://github.com/dhchenx). \n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Read and write CSV or TXT files in a simple manner",
    "version": "0.0.5",
    "project_urls": {
        "Bug Reports": "https://github.com/dhchenx/quick-csv/issues",
        "Homepage": "https://github.com/dhchenx/quick-csv",
        "Source": "https://github.com/dhchenx/quick-csv"
    },
    "split_keywords": [
        "csv file",
        "txt file",
        "write",
        "read",
        "quick-csv",
        "quickcsv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3eae2ae08479b33e6c05da9e9034d13d3166abf9bac88273f0387a1c0c63a896",
                "md5": "981eaa46be93dbe5ac49af61ea3b27fe",
                "sha256": "c1f80629677ef3416234716bc085eea79c5af9842b9c9b6783f657aed952a3fe"
            },
            "downloads": -1,
            "filename": "quick_csv-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "981eaa46be93dbe5ac49af61ea3b27fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6, <4",
            "size": 11793,
            "upload_time": "2022-08-30T09:58:08",
            "upload_time_iso_8601": "2022-08-30T09:58:08.759990Z",
            "url": "https://files.pythonhosted.org/packages/3e/ae/2ae08479b33e6c05da9e9034d13d3166abf9bac88273f0387a1c0c63a896/quick_csv-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ce8cb2c6ada29f6f37875cf558d3813e05b880af968f34ddc45b1b508c2d5ee6",
                "md5": "1218f2fc6f4a4f113a75ed6a3cb3c636",
                "sha256": "1b8919350268c6e59cd905941afd1e05b2a4c3a3cf46109a42bee54e73074dcb"
            },
            "downloads": -1,
            "filename": "quick-csv-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "1218f2fc6f4a4f113a75ed6a3cb3c636",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 12690,
            "upload_time": "2022-08-30T09:58:17",
            "upload_time_iso_8601": "2022-08-30T09:58:17.284883Z",
            "url": "https://files.pythonhosted.org/packages/ce/8c/b2c6ada29f6f37875cf558d3813e05b880af968f34ddc45b1b508c2d5ee6/quick-csv-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-30 09:58:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dhchenx",
    "github_project": "quick-csv",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "quick-csv"
}
        
Elapsed time: 0.08179s