Skip to main content

Quick CSV

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

Installation

pip install quick-csv

Examples for small files

Example 1: read and write csv or txt files

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

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

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

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

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.

Metadata

Release files for quick-csv 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quick-csv 0.0.5
File Size Uploaded
quick-csv-0.0.5.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quick-csv 0.0.5
File Interpreter ABI Platform
quick_csv-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 24.5 kB

Release files / quick-csv-0.0.5.tar.gz

Download URL quick-csv-0.0.5.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1b8919350268c6e59cd905941afd1e05b2a4c3a3cf46109a42bee54e73074dcb
BLAKE2b-256 checksum
How to use checksums
ce8cb2c6ada29f6f37875cf558d3813e05b880af968f34ddc45b1b508c2d5ee6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

Release files / quick_csv-0.0.5-py3-none-any.whl

Download URL quick_csv-0.0.5-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1f80629677ef3416234716bc085eea79c5af9842b9c9b6783f657aed952a3fe
BLAKE2b-256 checksum
How to use checksums
3eae2ae08479b33e6c05da9e9034d13d3166abf9bac88273f0387a1c0c63a896
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page