当前位置: 首页>>代码示例>>Python>>正文


Python feather.write_dataframe方法代码示例

本文整理汇总了Python中feather.write_dataframe方法的典型用法代码示例。如果您正苦于以下问题:Python feather.write_dataframe方法的具体用法?Python feather.write_dataframe怎么用?Python feather.write_dataframe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在feather的用法示例。


在下文中一共展示了feather.write_dataframe方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: health_xml_to_feather

# 需要导入模块: import feather [as 别名]
# 或者: from feather import write_dataframe [as 别名]
def health_xml_to_feather(zip_file, output_file, remove_zip=False):
    with tempfile.TemporaryDirectory() as tmpdirname:
        f = zipfile.ZipFile(zip_file, "r")
        f.extractall(tmpdirname)
        xml_path = os.path.join(tmpdirname, "apple_health_export/export.xml")
        tree = etree.parse(xml_path)
        records = tree.xpath("//Record")
        df = pd.DataFrame([{key: r.get(key) for key in ALL_KEYS}
                           for r in records])

        # Clean up key types
        for k in DATETIME_KEYS:
            df[k] = pd.to_datetime(df[k])
        for k in NUMERIC_KEYS:
            # some rows have non-numeric values, so coerce and drop NaNs
            df[k] = pd.to_numeric(df[k], errors="coerce")
            df = df[df["value"].notnull()]

        feather.write_dataframe(df, output_file)

    if remove_zip:
        os.remove(zip_file) 
开发者ID:mganjoo,项目名称:apple-health-exporter,代码行数:24,代码来源:export.py

示例2: save

# 需要导入模块: import feather [as 别名]
# 或者: from feather import write_dataframe [as 别名]
def save(data, filename):
    """Pickles the passed data (with the highest available protocol) to disk using the passed filename.
    If the filename ends in '.gz' then the data will additionally be GZIPed before saving.
    If filename ends with '.feather' or '.fthr', mlcrate will try to save the file using feather (for dataframes).
    Note that feather does not support compression.

    Keyword arguments:
    data -- The python object to pickle to disk (use a dict or list to save multiple objects)
    filename -- String with the relative filename to save the data to. By convention should end in '.pkl' or 'pkl.gz' or '.feather'
    """
    folders = os.path.dirname(filename)
    if folders:
        os.makedirs(folders, exist_ok=True)

    fl = filename.lower()
    if fl.endswith('.gz'):
        if fl.endswith('.feather.gz') or fl.endswith('.fthr.gz'):
            # Since feather doesn't support writing to the file handle, we can't easily point it to gzip.
            raise NotImplementedError('Saving to compressed .feather not currently supported.')
        else:
            fp = gzip.open(filename, 'wb')
            pickle.dump(data, fp, protocol=pickle.HIGHEST_PROTOCOL)
    else:
        if fl.endswith('.feather') or fl.endswith('.fthr'):
            if str(type(data)) != "<class 'pandas.core.frame.DataFrame'>":
                raise TypeError('.feather format can only be used to save pandas DataFrames')
            import feather
            feather.write_dataframe(data, filename)
        else:
            fp = open(filename, 'wb')
            pickle.dump(data, fp, protocol=pickle.HIGHEST_PROTOCOL) 
开发者ID:mxbi,项目名称:mlcrate,代码行数:33,代码来源:__init__.py

示例3: _dump_table

# 需要导入模块: import feather [as 别名]
# 或者: from feather import write_dataframe [as 别名]
def _dump_table(self, dst, fmt='feather', components=None, *args, **kwargs):
        """ Save batch data to table formats

        Args:
          dst: str - a path to dump into
          fmt: str - format: feather, hdf5, csv
          components: str or tuple - one or several component names
        """
        filename = dst

        components = tuple(components or self.components)
        data_dict = {}
        for comp in components:
            comp_data = self.get(component=comp)
            if isinstance(comp_data, pd.DataFrame):
                data_dict.update(comp_data.to_dict('series'))
            elif isinstance(comp_data, np.ndarray):
                if comp_data.ndim > 1:
                    columns = [comp + str(i) for i in range(comp_data.shape[1])]
                    comp_dict = zip(columns, (comp_data[:, i] for i in range(comp_data.shape[1])))
                    data_dict.update({comp: comp_dict})
                else:
                    data_dict.update({comp: comp_data})
            else:
                data_dict.update({comp: comp_data})
        _data = pd.DataFrame(data_dict)

        if fmt == 'feather':
            feather.write_dataframe(_data, filename, *args, **kwargs)
        elif fmt == 'hdf5':
            _data.to_hdf(filename, *args, **kwargs)   # pylint:disable=no-member
        elif fmt == 'csv':
            _data.to_csv(filename, *args, **kwargs)   # pylint:disable=no-member
        else:
            raise ValueError('Unknown format %s' % fmt)

        return self 
开发者ID:analysiscenter,项目名称:batchflow,代码行数:39,代码来源:batch.py

示例4: save_df

# 需要导入模块: import feather [as 别名]
# 或者: from feather import write_dataframe [as 别名]
def save_df(df, path, index=False):
    if path == '-' or path is None:
        print(default_csv_writer(df, None, index=index))
    elif file_format(path) != 'feather':
        default_csv_writer(df, path, index=index)
    elif featherpmm and feather:
        featherpmm.write_dataframe(featherpmm.Dataset(df, name='verification'),
                                   path)
    elif feather:
        feather.write_dataframe(df, path)
    else:
        raise Exception('The Python feather module is not installed.\n'
                        'Use:\n    pip install feather-format\n'
                        'to add capability.\n') 
开发者ID:tdda,项目名称:tdda,代码行数:16,代码来源:constraints.py

示例5: to_feather

# 需要导入模块: import feather [as 别名]
# 或者: from feather import write_dataframe [as 别名]
def to_feather(df, path):
    """
    Write a DataFrame to the feather-format

    Parameters
    ----------
    df : DataFrame
    path : string file path, or file-like object

    """
    path = _stringify_path(path)
    if not isinstance(df, DataFrame):
        raise ValueError("feather only support IO with DataFrames")

    feather = _try_import()
    valid_types = {'string', 'unicode'}

    # validate index
    # --------------

    # validate that we have only a default index
    # raise on anything else as we don't serialize the index

    if not isinstance(df.index, Int64Index):
        raise ValueError("feather does not support serializing {} "
                         "for the index; you can .reset_index()"
                         "to make the index into column(s)".format(
                             type(df.index)))

    if not df.index.equals(RangeIndex.from_range(range(len(df)))):
        raise ValueError("feather does not support serializing a "
                         "non-default index for the index; you "
                         "can .reset_index() to make the index "
                         "into column(s)")

    if df.index.name is not None:
        raise ValueError("feather does not serialize index meta-data on a "
                         "default index")

    # validate columns
    # ----------------

    # must have value column names (strings only)
    if df.columns.inferred_type not in valid_types:
        raise ValueError("feather must have string column names")

    feather.write_dataframe(df, path) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:49,代码来源:feather_format.py


注:本文中的feather.write_dataframe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。