pandas3d.frame package

Submodules

pandas3d.frame.frame module

pandasのDataFrameを画像データ用に拡張したもの

class pandas3d.frame.frame.GridFrame(data: Optional[numpy.ndarray] = None, columns: Optional[Union[List[str], str]] = None)[ソース]

ベースクラス: object

pandasのDataFrameに相当

パラメータ
  • data (np.ndarray) -- データ

  • columns (List) -- カラム名

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> type(gf)
<class 'pandas3d.frame.frame.GridFrame'>
>>> gf
a
[[ 0  2  4  6]
 [ 8 10 12 14]
 [16 18 20 22]]
b
[[ 1  3  5  7]
 [ 9 11 13 15]
 [17 19 21 23]]
shape(3, 4, 2), dtype('int64')
>>> GridFrame(columns=["a", "b"])
Traceback (most recent call last):
...
AssertionError: データのサイズとカラム数が不整合です
>>> GridFrame(np.arange(3), ["a", "b", "c"])
Traceback (most recent call last):
...
AssertionError: データの次元は2or3である必要があります
>>> GridFrame(np.arange(3).reshape(1, 3), ["a"])
a
[[0 1 2]]
shape(1, 3, 1), dtype('int64')
>>> GridFrame(np.arange(3).reshape(1, 3, 1), ["a", "b", "c"])
Traceback (most recent call last):
...
AssertionError: データのサイズとカラム数が不整合です
>>> GridFrame(np.arange(3).reshape(1, 1, 3), ["a", "b", "b"])
Traceback (most recent call last):
...
AssertionError: カラム名はユニークである必要があります
>>> GridFrame()
[]
None
add_prefix(prefix: str) pandas3d.frame.frame.GridFrame[ソース]

カラムにprefixを追加する

パラメータ

prefix (str) -- 追加するprefix

戻り値

追加したGridFrame

戻り値の型

GridFrame

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> gf_add_prefix = gf.add_prefix("test_")
>>> gf_add_prefix.columns
['test_a', 'test_b']
append(gf: pandas3d.frame.frame.GridFrame) pandas3d.frame.frame.GridFrame[ソース]

追加する

パラメータ

gf (GridFrame) -- 追加するGridFrame

戻り値

追加したGridFrame

戻り値の型

GridFrame

check_isfinite() None[ソース]

nan, inf, -infが含まれている場合に例外を投げる

サンプル

>>> GridFrame(np.array([[np.inf]]), ["a"]).check_isfinite()
Traceback (most recent call last):
...
ValueError: nanやinfが含まれています
property columns: List[str]

カラム名を返す

戻り値

カラム名

戻り値の型

List(str)

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> gf.columns
['a', 'b']
>>> type(gf.columns)
<class 'list'>
copy() pandas3d.frame.frame.GridFrame[ソース]

コピーする

戻り値

コピーしたGridFrame

戻り値の型

GridFrame

警告

GridFrameのコピーはdeepcopyです。

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> gf_copy = gf.copy()
>>> gf_copy is gf
False
>>> gf_copy == gf
True
>>> gf_copy.values is gf.values
False
>>> (gf_copy.values == gf.values).all()
True
>>> gf_copy.columns is gf.columns
False
>>> gf_copy.columns == gf.columns
True
draw_distribution(save_dir: pathlib.Path, is_axis: bool = True, extension: str = 'png') None[ソース]

分布を画像として保存する

パラメータ
  • save_dir (Path) -- 描画した画像を保存するディレクトリ

  • is_axis (bool) -- 分布を描画するかどうか

  • extension (str) -- 拡張子

extract_columns_endswith(txt: str) pandas3d.frame.frame.GridFrame[ソース]

txtで終わるカラムを抽出する

パラメータ

txt (str) -- 抽出する文字列

戻り値

抽出したGridFrame

戻り値の型

GridFrame

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["test_a", "test_b"])
>>> gf_extract = gf.extract_columns_endswith("a")
>>> gf_extract.columns
['test_a']
>>> gf_extract.shape
(3, 4, 1)
extract_columns_startswith(txt: str) pandas3d.frame.frame.GridFrame[ソース]

txtで始まるカラムを抽出する

パラメータ

txt (str) -- 抽出する文字列

戻り値

抽出したGridFrame

戻り値の型

GridFrame

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a_test", "b_test"])
>>> gf_extract = gf.extract_columns_startswith("a")
>>> gf_extract.columns
['a_test']
>>> gf_extract.shape
(3, 4, 1)
property iloc: pandas3d.frame.frame.Iloc

インデクシング

戻り値

インデクシングされたGridFrame

戻り値の型

GridFrame

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> type(gf.iloc[:, 1:3, 0:1])
<class 'pandas3d.frame.frame.GridFrame'>
>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> type(gf.iloc[:, 1, 0:1])
Traceback (most recent call last):
...
ValueError: 3次元以上のデータが必要です
property shape: Tuple[int, ...]

shapeを返す

戻り値

shape

戻り値の型

Tuple[int, ...]

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> gf.shape
(3, 4, 2)
to_pandas() pandas.core.frame.DataFrame[ソース]

pandasのDataFrameに変換する

  • gf:shape(a, b, c) -> pd.shape(a * b, c)

戻り値

pandasのDataFrame

戻り値の型

pd.DataFrame

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> df = gf.to_pandas()
>>> type(df)
<class 'pandas.core.frame.DataFrame'>
>>> df.shape
(12, 2)
>>> list(df.columns)
['a', 'b']
property values: numpy.ndarray

pandasのvaluesに相当

戻り値

配列部を返す

戻り値の型

np.ndarray

サンプル

>>> array = np.arange(24).reshape(3, 4, 2)
>>> gf = GridFrame(array, ["a", "b"])
>>> (gf.values == array).all()
True
>>> type(gf.values)
<class 'numpy.ndarray'>
class pandas3d.frame.frame.Iloc(gf: pandas3d.frame.frame.GridFrame)[ソース]

ベースクラス: object

インデクシングを行うクラス

  • gf.ilocで呼ばれる

パラメータ

gf (GridFrame) -- GridFrame

pandas3d.frame.frame.check_nan(func: Callable) Callable[ソース]

valuesがnanの場合に例外を投げるデコレーター用の関数

パラメータ

func (Callable) -- 実行する関数

戻り値

実行する関数

戻り値の型

Callable

例外

ValueError -- nanが含まれている場合

pandas3d.frame.frame.empty(shape: tuple[int, ...], columns: Optional[Union[List, str]] = None) pandas3d.frame.frame.GridFrame[ソース]

空のGridFrameを作成する

パラメータ
  • shape (tuple[int, ...]) -- shape

  • columns (Optional[Union[List, str]]) -- カラム名

戻り値

空のGridFrame

戻り値の型

GridFrame

サンプル

>>> gf = empty((3, 4))
>>> gf.columns
[]
>>> gf.shape
(3, 4, 0)
pandas3d.frame.frame.from_pandas(df: pandas.core.frame.DataFrame, shape: tuple[int, int]) pandas3d.frame.frame.GridFrame[ソース]

pandasのDataFrameからGridFrameを作成する

  • カラムはそのまま

  • shape=(a, b)のとき(a * b, c) -> (a , b, c)に変換する

パラメータ
  • df (pd.DataFrame) -- pandasのDataFrame

  • shape (tuple[int, int]) -- shape

戻り値

GridFrame

戻り値の型

GridFrame

サンプル

>>> df = pd.DataFrame(np.arange(24).reshape(12, 2), columns=["a", "b"])
>>> gf = from_pandas(df, shape=(3, 4))
>>> gf.shape
(3, 4, 2)
>>> gf.columns
['a', 'b']
pandas3d.frame.frame.zeros(shape: tuple[int, ...], columns: Optional[Union[List, str]] = None) pandas3d.frame.frame.GridFrame[ソース]

0を入れるGridFrameを作成する

パラメータ
  • shape (tuple[int, ...]) -- shape

  • columns (Optional[Union[List, str]]) -- カラム名

戻り値

0を入れたGridFrame

戻り値の型

GridFrame

サンプル

>>> gf = zeros((3, 4, 2), ["a", "b"])
>>> gf.values.sum()
0.0

Module contents