Package to convert csv and directories to each other.
Project description
CSVと階層フォルダの相互変換
このモジュールについて
このプロジェクトは、CSVファイルと階層フォルダを相互変換するpythonモジュール。具体的には、ルールに沿って作成されたディレクトリからcsvファイルへの書き起こし、そして、ある一定のルールベースに沿って作成されたcsvからディレクトリを作成する。
csvからディレクトリへ変換
csvファイルから階層をパースして、ディレクトリとプロパティファイルを作成する
-
csv
index, no, pos, param1, param2, param3, 1, 1.1, 1, p1_1, p1_2, p1_3 2, 2.2, 2, p2_1, p2_2, p2_3
-
csvをディレクトリに変換
. |-- 1 | |--1.1 | |-- attribute.json(機械学習用パラメータ) |-- 2 | |--2.1 | |-- attribute.json(機械学習用パラメータ)attribute.jsonの内容{ "index": "1", "no": "1.1", "pos": "1", "param1": "p1_1", "param2": "p1_2", "param3": "p1_3" }
-
ディレクトリ階層をパースして、CSVファイルを作成
上記変換ステップの逆順で実行する
動作条件
- python >= 3.8
インストール
※ 本パッケージは、仮想環境を作成して実行することを推奨します。
- PyPI
pip install convoc
- Gitlab Package Registory
pip install convoc --index-url https://__token__:<your_personal_token>@gitlab.com/api/v4/projects/37267127/packages/pypi/simple
GitLabは、プライベートリポジトリであるため、インストール時に、個人のアクセストークン(your_personal_token)を使用してインストールしてください。
Usage
CSVからディレクトリ階層へ
Format
def csv2dir(csvfile: str, level: int, root_dir: str, *, isheader: bool = False, attribute_type: str = "json") -> List[Dict[str, str]]:
Input
csvfile (str): CSVファイルlevel (int): 作成するディレクトリ階層の指定root_dir (str): ディレクトリを作成する親ディレクトリisheader (bool, optional): CSVのヘッダー情報有無attribute_type (str, optional): 属性ファイル(e.g. attribue.json)のファイルタイプ。json/toml/yaml/csv/textをサポート。
Output
- 読み込んだcsvファイルのコンテンツ
Exsample
from convoc import csv2dir
# csv file to be read
read_filepath = 'csv/sample.csv'
# Convert directory from csv
csv_contents = csv2dir(csvfile=read_filepath, level=2, target_path="target", is_header=True)
# loaded csv file (type: list)
print(csv_contents)
ディレクトリ階層からcsvへ
Format
def dir2csv(root_dir: str, output: str, *, level: Optional[int] = None, attribute_type: str = "json") -> List[Any]:
Input
root_dir (str): 読み込み対象となるルートディレクトリoutput (str): 変換したcsvの格納先ディレクトリlevel (Optional[int], optional): csvに書き出す階層の指定attribute_type (str, optional): 読み取り対象の属性ファイル
Output
- 変換後のディレクトリのリスト
Exsample
# exsample.py
from convoc import dir2csv
# Convert directory structure to csv
result = dir2csv(root_dir='target', output='csv/recover.csv', level=2)
# Output list of converted directories
# At the same time, csv/recover.csv is generated.
print(result)
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
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 convoc-0.0.1.tar.gz.
File metadata
- Download URL: convoc-0.0.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a415399ffe02e01a8cb4548925833142814ea7cc7243dbedab06e92a749f51f1
|
|
| MD5 |
ac55b1e697441e2705473f0374c13fa2
|
|
| BLAKE2b-256 |
ca142957d92ad5122ca4ad8cd2a938544c22567a2cc33f62b834b25b51fa2fe6
|
File details
Details for the file convoc-0.0.1-py3-none-any.whl.
File metadata
- Download URL: convoc-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3a07857f8d1f286d96b6ea096219ef22109a9b276769753eda439b111a8bbd3
|
|
| MD5 |
b062f6b1cf73c8169cbde90c66018403
|
|
| BLAKE2b-256 |
db0c94221b0976bfe07fa2748e6b5e402f1b6618d380f9d1571fda27878727b5
|