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
Release history Release notifications | RSS feed
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.2.tar.gz
(2.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csvkey-0.0.2.tar.gz.
File metadata
- Download URL: csvkey-0.0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cc1d1a51adf14952a2854cf022f4d0f1e9c56b05cebaaaaaece9695fd1b71d5
|
|
| MD5 |
c0c6b5c1ffc1ede606b650509867f5f1
|
|
| BLAKE2b-256 |
7ed0027ccea0f427e0d530ae799b7f84d5d8b5b4882224ababa2e8255f95ae33
|
File details
Details for the file csvkey-0.0.2-py3-none-any.whl.
File metadata
- Download URL: csvkey-0.0.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d927337fd79c73bc3f35459fcfc5220e12523078fa019072bec92b5828cbd35
|
|
| MD5 |
c20afe7bf55ca879858d1149769788cb
|
|
| BLAKE2b-256 |
19053c0c3ab66350c182b02c3f86c4e2fc269fb7526cb50324b36eaeeb88c829
|