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 = py_xsv.content_dict("data.csv")
print(data[:5])

Read as a list of lists

import py_xsv

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

Detect dilimiter manualy

import py_xsv

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

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

Work with columns and headers

import py_xsv

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

Quick access to top and bottom rows

import py_xsv

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

Save data to a pandas DataFrame

import pandas
import py_xsv

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

You need to have import pandas before doing this

Exceptions

  • py_xsv.NotSVFileError - Used when a non -sv file is given
  • py_xsv.PandaError - Errors while using pandas
  • py_xsv.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.2.tar.gz (3.9 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.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_xsv-0.0.2.tar.gz
  • Upload date:
  • Size: 3.9 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.2.tar.gz
Algorithm Hash digest
SHA256 7e2bd4e1e589d94aa2301e72f7ac53b4da45a8349fa47c1bc5ba97e53fc8e423
MD5 6271d561045097acdf3885b8d329f3a4
BLAKE2b-256 dfdced3c0342a24f6b387baa3c7178c5b3a5a02b6b4860e9161a877add7b7ad3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_xsv-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b29e9085be9c4a58e7301bd676315959785f47a61f04c63234381b25cda061f
MD5 853af7bbe3eb6a5d6e9451c9d4a0f0ed
BLAKE2b-256 447ce2ac4e4ca79be48fe41b524169e7d763f788a4051c53faf5b9529a8a3113

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