Skip to main content

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)

Metadata

Release files for convoc 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for convoc 0.0.1
File Size Uploaded Provenance Actions
convoc-0.0.1.tar.gz 10.5 kB Without provenance Details for convoc-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for convoc 0.0.1
File Interpreter ABI Platform Actions
convoc-0.0.1-py3-none-any.whl Python 3 none any Details for convoc-0.0.1-py3-none-any.whl

Total release size: 21.7 kB

Release files / convoc-0.0.1.tar.gz

Download URL convoc-0.0.1.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a415399ffe02e01a8cb4548925833142814ea7cc7243dbedab06e92a749f51f1
BLAKE2b-256 checksum
How to use checksums
ca142957d92ad5122ca4ad8cd2a938544c22567a2cc33f62b834b25b51fa2fe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / convoc-0.0.1-py3-none-any.whl

Download URL convoc-0.0.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3a07857f8d1f286d96b6ea096219ef22109a9b276769753eda439b111a8bbd3
BLAKE2b-256 checksum
How to use checksums
db0c94221b0976bfe07fa2748e6b5e402f1b6618d380f9d1571fda27878727b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for convoc 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page