當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。