Skip to main content

Reading -sv files and writing them to dataframes

Project description

py-xsv

py-xsv is a Python utility for reading -SV files (CSV, TSV, etc.) and converting them into dataframes.


Features

  • Auto-detect delimiters in CSV, TSV, or other -SV files.
  • Read files into:
    • List of dictionaries (content_dict)
    • List of lists (content_list)
  • Extract column data easily (column).
  • Quickly access top/bottom rows (head, tail).
  • Get dimensions (length_width) and headers (headers).
  • Save -SV file to pandas DataFrames (save_df).

Installation

pip install py-xsv

This needs Python 3.9 or more.


Docs

Read a CSV/TSV file as a list of dictionaries

import py_xsv
data = content_dict("data.csv")
print(data[:5])

Read as a list of lists

import py_xsv

data = content_list("data.csv")
print(data[:5])

Detect dilimiter manualy

import py_xsv

with open("data.csv", "r") as f:
    lines = f.readlines()

delimiter = detect_delimiter(lines)
print(f"Detected delimiter: {delimiter}")

Work with columns and headers

import py_xsv

data = content_dict("data.csv")
print("Headers:", headers(data))
print("First column:", column(data, "ColumnName"))

Quick access to top and bottom rows

import py_xsv

data = content_list("data.csv")
print("Top 5 rows:", head(data, 5))
print("Bottom 5 rows:", tail(data, 5))

Save data to a pandas DataFrame

import pandas
import py_xsv

data = content_dict("data.csv")
df = save_df(data)

You need to have import pandas before doing this

Exceptions

  • NotSVFileError - Used when a non -sv file is given
  • PandaError - Errors while using pandas
  • Error - Generic Error

License

This is licensed under the WTFPL.

This means that you have permission for:

  • Commercial use
  • Modification
  • Distribution
  • Private use
  • Everything basically

Under no conditions or limitations


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_xsv-0.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_xsv-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file py_xsv-0.0.1.tar.gz.

File metadata

  • Download URL: py_xsv-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for py_xsv-0.0.1.tar.gz
Algorithm Hash digest
SHA256 770724f83296e21cfd796932d6d28229dbe4626b0a450b834eb37931e7277a17
MD5 9885b0809e8352209899ec8e467486b3
BLAKE2b-256 7e3dcdbb3c4463dd7e93c9a5edba37a9f01965baff265d316d144c9127d51f17

See more details on using hashes here.

File details

Details for the file py_xsv-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_xsv-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for py_xsv-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b273739700f377bb2f7c6e9ca652fae466e1ef770393b0b4cdbaef87b90530c8
MD5 668967cb88f40669845a0fde9a275f49
BLAKE2b-256 4dcda8253a5b14488f3100c3e4a2693f80311820713ecc6cd97d27a3cef6439e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page