renom_cn.api.file_operator ¶
Copyright 2019, Grid.
This source code is licensed under the ReNom Subscription Agreement, version 1.0. ReNom Subscription Agreement Ver. 1.0 ( https://www.renom.jp/info/license/index.html )
-
class
renom_cn.api.file_operator.
ParquetReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of Parquet file read/write module.
- Examples:
-
>>> import os >>> import pandas as pd >>> from renom_cn.api.file_operator import ParquetReadWrite >>> test_data = {"col1": [1, 2], "col2": [3, 4]} >>> test_df = pd.DataFrame(data=test_data) >>> test_df col1 col2 0 1 3 1 2 4 >>> rw = ParquetReadWrite(fstype="local") >>> filepath = "/tmp/data.parquet" >>> rw.write(filepath, test_df) >>> os.path.exists(filepath) True >>> rw.read(filepath) col1 col2 0 1 3 1 2 4 >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read parquet file.
- Args:
-
- path : string.
- filepath.
- Returns:
- data : pandas.DataFrame.
-
write
( path , data ) ¶ -
Write pandas DataFrame to Parquet file.
- Args:
-
- path : string.
- filepath.
data: pandas.DataFrame.
-
class
renom_cn.api.file_operator.
CSVReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of csv file read/write module.
- Examples:
-
>>> import os >>> import pandas as pd >>> from renom_cn.api.file_operator import CSVReadWrite >>> test_data = {"col1": [1, 2], "col2": [3, 4]} >>> test_df = pd.DataFrame(data=test_data) >>> test_df col1 col2 0 1 3 1 2 4 >>> rw = CSVReadWrite(fstype="local") >>> filepath = "/tmp/data.csv" >>> rw.write(filepath, test_df) >>> os.path.exists(filepath) True >>> rw.read(filepath) col1 col2 0 1 3 1 2 4 >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read csv file.
- Args:
-
- path : string.
- filepath.
- Returns:
- data : pandas.DataFrame.
-
write
( path , data ) ¶ -
Write pandas DataFrame to csv file.
- Args:
-
- path : string.
- filepath.
data: pandas.DataFrame.
-
class
renom_cn.api.file_operator.
PickleReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of pickle file read/write module.
- Examples:
-
>>> import os >>> import pandas as pd >>> from renom_cn.api.file_operator import PickleReadWrite >>> test_data = {"col1": [1, 2], "col2": [3, 4]} >>> test_df = pd.DataFrame(data=test_data) >>> test_df col1 col2 0 1 3 1 2 4 >>> rw = PickleReadWrite(fstype="local") >>> filepath = "/tmp/data.pickle" >>> rw.write(filepath, test_df) >>> os.path.exists(filepath) True >>> rw.read(filepath) col1 col2 0 1 3 1 2 4 >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read pickle file.
- Args:
-
- path : string.
- filepath.
- Returns:
- data : pandas.DataFrame.
-
write
( path , data ) ¶ -
Write pandas DataFrame to pickle file.
- Args:
-
- path : string.
- filepath.
data: pandas.DataFrame.
-
class
renom_cn.api.file_operator.
JsonReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of json file read/write module.
- Examples:
-
>>> import os >>> from renom_cn.api.file_operator import JsonReadWrite >>> test_dict = {"test": {"key1": "val1", "key2": "val2"} } >>> rw = JsonReadWrite(fstype="local") >>> filepath = "/tmp/data.json" >>> rw.write(filepath, test_dict) >>> os.path.exists(filepath) True >>> rw.read(filepath) {'test': {'key1': 'val1', 'key2': 'val2'}} >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read json file to dict.
- Args:
-
- path : string.
- filepath.
- Returns:
- data : dict.
-
write
( path , data ) ¶ -
write json file from dict.
- Args:
-
- path : string.
- filepath.
- data: dict.
- dict of json data.
-
class
renom_cn.api.file_operator.
XmlReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of xml file read/write module.
- Examples:
-
>>> import os >>> from renom_cn.api.file_operator import XmlReadWrite >>> test_dict = {"test": {"key1": "val1", "key2": "val2"} } >>> rw = XmlReadWrite(fstype="local") >>> filepath = "/tmp/data.xml" >>> rw.write(filepath, test_dict) >>> os.path.exists(filepath) True >>> rw.read(filepath) OrderedDict([('test', OrderedDict([('key1', 'val1'), ('key2', 'val2')]))]) >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read xml file to dict.
- Args:
-
- path : string.
- filepath.
- Returns:
- data : dict.
-
write
( path , data ) ¶ -
write xml file from dict.
- Args:
-
- path : string.
- filepath.
- data: OrderedDict.
- OrderedDict of xml data.
-
class
renom_cn.api.file_operator.
ImageReadWrite
( fstype='local' ) ¶ -
ベースクラス:
renom_cn.api.file_operator.ReadWriteBase
Class of image file read/write module.
- Examples:
-
>>> import os >>> import numpy as np >>> import PIL.Image >>> from renom_cn.api.file_operator import ImageReadWrite >>> test_img_array = np.random.randint(0, 255, (128, 128, 3)).astype(np.uint8) >>> test_img = PIL.Image.fromarray(np.uint8(test_img_array)) >>> rw = ImageReadWrite(fstype="local") >>> filepath = "/tmp/data.png" >>> rw.write(filepath, test_img, "png") >>> os.path.exists(filepath) True >>> rw.read(filepath) <PIL.PngImagePlugin.PngImageFile image mode=RGB size=128x128 at 0x11314F240> >>> rw.fs.rm(filepath) >>> os.path.exists(filepath) False
-
read
( path ) ¶ -
read img file to PIL.Image.
- Args:
-
- path : string.
- filepath.
- Returns:
- img : PIL.Image.
-
write
( path , img , extension ) ¶ -
write img file from PIL.Image.
- Args:
-
- path : string.
- filepath.
- img : PIL.Image.
- image object.
- extension : string.
- file extension.