Skip to main content

use PRIMARY KEY and UNIQUE in CSV

Project description

##csvkey For a very limited situation such that you don't need performance and want to use CSV as database.

##Example

from csvkey import Connection
import pandas as pd
import numpy as np


# prepare DataFrame
data = pd.DataFrame()
data['A'] = pd.Series([1,2,3], dtype='int')
data['B'] = pd.Series([4,5,6], dtype='float32')
data['C'] = pd.Series([7,8,9], dtype='float64')


# register database
conn = Connection()
conn.initialize(data, r'C:\TEST\database.csv',
                primary=['A', 'B'],
                unique=['C'],
                notnull=['C'])
# database.csv and the configuration file (default: csv.conf) are generated in C:\TEST\
# set 'A' and 'B' columns as a primary key
# values in 'C' column must be unique and not NaN


# connect to database.csv
conn.connect(r'C:\TEST\database.csv')
conn.df.dtypes # dtypes are preserved


# change values in conn.df
conn.df.loc[0, 'C'] = 8
conn.commit() # raise ValueError because 8 is not unique
conn.df.loc[0, 'C'] = np.nan 
conn.commit() # raise ValueError because NaN is not allowed in 'C'
conn.df.loc[0, 'C'] = -1
conn.commit() # OK
conn.df.loc[2, ['A', 'B']] = [1, 4]
conn.commit() # raise ValueError because primary keys are duplicated

Installation

pip install csvkey

Requirements

pandas pyyaml

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

csvkey-0.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

csvkey-0.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: csvkey-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for csvkey-0.0.1.tar.gz
Algorithm Hash digest
SHA256 006e0c0e7a41a3e99cbf306b1fbfe6150229f579ac433be25b04a8f184986f70
MD5 271972a4b86fd8c5e05b8de8cbf88372
BLAKE2b-256 d1a16ca0b826091f315d81d624fca69636b1c73ae98d9a63c3dfb5b18f485f8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: csvkey-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for csvkey-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85407ca43b6c9dc4e964981eec9bf0bb51a820402517c614c8401ed1a2ce34ba
MD5 8d5fa432b5f178c6828d54e066a1edc0
BLAKE2b-256 e3b366b06e8f805e4acdd5996455c47988f1297de84d52b789e15ae7f8f224d6

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