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


Python pandas.ExcelWriter方法代码示例

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


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

示例1: save_cluster_xlsx

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def save_cluster_xlsx(
    filepath: str, de_results: List[pd.DataFrame], cluster_names: List
):
    """Saves multi-clusters DE in an xlsx sheet

    Parameters
    ----------
    filepath
        xslx save path
    de_results
        list of pandas Dataframes for each cluster
    cluster_names
        list of cluster names
    """
    writer = pd.ExcelWriter(filepath, engine="xlsxwriter")
    for i, x in enumerate(cluster_names):
        de_results[i].to_excel(writer, sheet_name=str(x))
    writer.close() 
开发者ID:YosefLab,项目名称:scVI,代码行数:20,代码来源:posterior_utils.py

示例2: write_excel

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def write_excel(filename, **kwargs):
    """Write data tables to an Excel file, using kwarg names as sheet names.
    
    Parameters
    ----------
    filename : str
        The filename to write to.
    kwargs : dict
        Mapping from sheet names to data.
    """
    writer = pd.ExcelWriter(filename)
    for sheet_name, obj in kwargs.items():
        if isinstance(obj, dict):
            obj = _params_dict_to_dataframe(obj)
        if isinstance(obj, pd.DataFrame):
            obj.to_excel(writer, sheet_name=sheet_name)
    writer.save()
    writer.close() 
开发者ID:jni,项目名称:skan,代码行数:20,代码来源:io.py

示例3: export_text2xlsx

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def export_text2xlsx(infile, outfile, field_delimiter, number):
    df = pd.read_csv(infile, delimiter=field_delimiter, engine='python')
    rows_number = df.shape[0]
    if rows_number > number:
        data_frames = split_dataframe(df, number)
        frame_number = 1
        for frame in data_frames:
            filename, ext = os.path.splitext(outfile)
            excel_file = "{}_{}.xlsx".format(filename, frame_number)
            writer = ExcelWriter(excel_file, engine='xlsxwriter')
            frame.to_excel(writer, 'sheet1')
            writer.save()
            frame_number += 1
    else:
        writer = ExcelWriter(outfile)
        df.to_excel(writer, 'sheet1')
        writer.save() 
开发者ID:motazsaad,项目名称:tweets-collector,代码行数:19,代码来源:text2xlsx.py

示例4: spia_matrices_to_excel

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def spia_matrices_to_excel(spia_matrices: SPIADataFrames, path: str) -> None:
    """Export a SPIA data dictionary into an Excel sheet at the given path.

    .. note::

        # The R import should add the values:
        # ["nodes"] from the columns
        # ["title"] from the name of the file
        # ["NumberOfReactions"] set to "0"
    """
    writer = pd.ExcelWriter(path, engine='xlsxwriter')

    for relation, df in spia_matrices.items():
        df.to_excel(writer, sheet_name=relation, index=False)

    # Save excel
    writer.save() 
开发者ID:pybel,项目名称:pybel,代码行数:19,代码来源:spia.py

示例5: full_report_to_xls

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def full_report_to_xls(tsd, output_folder, basename):
    """ this function is to write a full report to an ``*.xls`` file containing all intermediate and final results of a
    single building thermal loads calculation"""

    df = pd.DataFrame(tsd)

    # Create a Pandas Excel writer using XlsxWriter as the engine.
    #timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    #output_path = os.path.join(output_folder,"%(basename)s-%(timestamp)s.xls" % locals())
    output_path = os.path.join(output_folder, "%(basename)s.xls" % locals())
    writer = pd.ExcelWriter(output_path, engine='xlwt')

    df.to_excel(writer, na_rep='NaN')

    # Close the Pandas Excel writer and output the Excel file.
    writer.save()
    writer.close() 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:19,代码来源:reporting.py

示例6: _resize_columns

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def _resize_columns(self, sheetname_dataframe, writer, max_width, text_wrap=True):
        """
        Resizes columns in workbook.
        :param sheetname_dataframe: A map mapping the sheet name to a dataframe.
        :param writer: The ExcelWriter, which the worksheets already added using writer.to_excel
        :param max_width: The maximum width of the columns.
        :param text_wrap: Whether or not to turn on text wrapping if columns surpass max_width.
        :return: None
        """
        workbook = writer.book
        wrap_format = workbook.add_format({'text_wrap': text_wrap})
        for name in sheetname_dataframe:
            for i, width in enumerate(self._get_col_widths(sheetname_dataframe[name])):
                if width > max_width:
                    writer.sheets[name].set_column(i, i, width=max_width, cell_format=wrap_format)
                else:
                    writer.sheets[name].set_column(i, i, width=width) 
开发者ID:phac-nml,项目名称:staramr,代码行数:19,代码来源:Search.py

示例7: __init__

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def __init__(self, kwargs, *, cp_dir, log_dir, excel_dir, logger2file):
        self.log_dir = log_dir
        self.writer = tf.summary.create_file_writer(log_dir)
        # self.writer.set_as_default()
        self.checkpoint = tf.train.Checkpoint(**kwargs)
        self.saver = tf.train.CheckpointManager(self.checkpoint, directory=cp_dir, max_to_keep=5, checkpoint_name='ckpt')
        self.excel_writer = pd.ExcelWriter(excel_dir + '/data.xlsx')
        self.logger = self.create_logger(
            name='logger',
            console_level=logging.INFO,
            console_format='%(levelname)s : %(message)s',
            logger2file=logger2file,
            file_name=log_dir + 'log.txt',
            file_level=logging.WARNING,
            file_format='%(lineno)d - %(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s'
        ) 
开发者ID:StepNeverStop,项目名称:RLs,代码行数:18,代码来源:recorder.py

示例8: pack_measures

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def pack_measures(self):
        writer = pd.ExcelWriter(self.excel_name, engine='xlwt')
        self.measure_pd.to_excel(writer, sheet_name='measures', index=False, engine='xlwt')

        # Add the total column and row
        if self.path_template is not None:
            for sheet_name in self.distrib_matrix_dct:
                if '#' in sheet_name:
                    df = self.distrib_matrix_dct[sheet_name].copy()
                    df = df.append(df.sum(numeric_only=True, axis=0), ignore_index=True)
                    df['total'] = df.sum(numeric_only=True, axis=1)
                    df.iloc[-1, df.columns.get_loc('vert')] = 'total'
                    df.to_excel(writer, sheet_name=sheet_name, index=False, engine='xlwt')
                else:
                    self.distrib_matrix_dct[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False, engine='xlwt')

        # Save pickle
        self.distrib_matrix_dct['measures'] = self.measure_pd
        with open(self.pickle_name, 'wb') as handle:
            pickle.dump(self.distrib_matrix_dct, handle)

        # Save Excel
        writer.save() 
开发者ID:neuropoly,项目名称:spinalcordtoolbox,代码行数:25,代码来源:sct_analyze_lesion.py

示例9: write_data

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def write_data(self, file_descr):
        """
        Use dataframe to_excel to write into file_descr (filename) - open first if file exists.
        """
        if os.path.isfile(file_descr):
            print(file_descr, 'exists')
            # Solution to keep existing data
            book = load_workbook(file_descr)
            writer = pd.ExcelWriter(file_descr, engine='openpyxl')
            writer.book = book
            writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
            self.data_df.to_excel(writer, sheet_name='Mongo_Schema', index=True,
                                  float_format='%.2f')
            writer.save()
        else:
            self.data_df.to_excel(file_descr, sheet_name='Mongo_Schema', index=True,
                                  float_format='%.2f') 
开发者ID:pajachiet,项目名称:pymongo-schema,代码行数:19,代码来源:export.py

示例10: write_results

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def write_results(results, summary, output):
    writer = pd.ExcelWriter(output, engine='xlsxwriter')
    cell_fmt = writer.book.add_format({
        "font_name": "Arial",
        "font_size": "10"
    })
    index_fmt = writer.book.add_format({
        "font_name": "Arial",
        "font_size": "10",
        "bold": True,
    })
    header_fmt = writer.book.add_format({
        "font_name": "Arial",
        "font_size": "10",
        "bold": True,
        "bottom": 1
    })

    add_sheet(summary, 'Number of wins per version', writer, cell_fmt, index_fmt, header_fmt)

    for version in reversed(sorted(results.keys())):
        add_sheet(results[version], version, writer, cell_fmt, index_fmt, header_fmt)

    writer.save() 
开发者ID:sdv-dev,项目名称:SDGym,代码行数:26,代码来源:results.py

示例11: create

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def create(self):

        # A memory buffer as ExcelWriter storage backend
        buffer = BytesIO()
        self.workbook.filename = buffer

        # Create "cover" sheet
        self.write_cover_sheet()

        # Create "queries" sheet
        self.write_queries_sheet()

        # Create numberlist sheets
        self.write_numberlist_sheets()

        # Create "comments" sheet
        self.write_comments_sheet()

        # Save/persist ExcelWriter model
        self.writer.save()

        # Get hold of buffer content
        payload = buffer.getvalue()
        return payload 
开发者ID:ip-tools,项目名称:patzilla,代码行数:26,代码来源:export.py

示例12: write_to_excel

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def write_to_excel(comp_values):
    current_dir = os.path.realpath(os.path.dirname(__file__))
    df = pd.DataFrame(comp_values)
    with pd.ExcelWriter(os.path.join(current_dir, "output" + ".xlsx")) as writer:
        for col in df:
            df1 = pd.concat([df[col], df[col].apply(pd.Series)], axis=1).drop(
                [col], axis=1
            )
            df1.to_excel(writer, sheet_name=col)
            worksheet = writer.sheets[col]
            worksheet.set_column(0, 19, 16)


# Tests for running the plots independently
# if __name__ == "__main__":
#    write_to_excel({'ieee_4node': {'cyme_output': {'1': [1.796043190045738, 5.388117303585387, 0.10784685850195197, 0.5904760366014294], '2': [2.0202605985010313, 6.518985500570162, 0.22820004614399358, 0.8158267453203445], '3': [0.2536631703405771, 0.8984713888134145, 0.06581202655980385, 0.24831713333607722], '4': [0.5340964354229437, 2.3119539172019614, 0.23396047634518685, 0.46239954705589636]}, 'demo_output': {}, 'gridlabd_output': {'sourcebus': [1.7960358301233543, 5.388107490370064, 1.6037668205527515, 6.415067282211007], 'node2': [11.615625751028661, 11.520529778987775, 9.073598525409436, 5.8609512435066655], 'node3': [1.2918305507375225, 1.2769209930818217, 1.0089298663668416, 0.6470699623879508], 'load4': [0.8640026377752124, 0.41845221416471984, 0.8640056993976751, 0.4184497947877163], 'node1': [11.95788550650638, 12.207304856874984, 9.189536257036401, 6.043847565567804]}, 'opendss_output': {'sourcebus': [0.0002463564270509644, 0.0007390394604267333, 0.00018858267905109123, 0.0007542723977164494], 'n2': [0.29564583680274237, 0.7167450994489304, 0.11638654713225582, 0.2358768460293939], 'n3': [0.06870713919610347, 0.23863115122119738, 0.048858783362332986, 0.18910852255356034], 'n4': [0.5051857600366919, 0.7781653125896516, 0.21133259350889166, 0.4141945608522559]}, 'synergi_output': {'node_61746791326': [0.000999999415454687, 0.0009999923015324673, 0.0009999996415073831, 0.0009999921771822826], 'node_61746791327': [1.4052433405517772, 0.8534261345199505, 1.100207413576314, 0.09925701086833777], 'node_61746839533': [0.5767771891663984, 1.2140898058567755, 0.5400898631419725, 1.138540681909626], 'node_61746842036': [2.2802968553458975, 1.9930774142792114, 1.8176517572334512, 1.1452767401123385]}}, 'ieee_13node': {'cyme_output': {'650': [1.6442002249862027, 2.525071217368887, 0.00175590064769382, 0.013818660541591976], '633': [2.191962671993786, 2.7645145724914206, 0.13502678340376117, 0.30258402028428943], '634': [0.03373885959967424, 0.0437948202860033, 0.006851233217346727, 0.01281928879314106], '7': [1.6444948113338582, 2.5248296649991535, 0.0027565424317121945, 0.014811194353743895], 'rg60': [1.6444956621823732, 2.524829864977333, 0.002756707027920302, 0.014813876873885912], '632': [2.1103087225772716, 2.527515777000864, 0.0791161472443358, 0.2320482533916044], '652': [1.2506186991395154, 1.2878722947329384, 1.2506186991395154, 1.2878722947329384], '611': [1.1239472985549395, 1.3770646713358636, 1.1239472985549395, 1.3770646713358636], '692': [2.631742710227492, 2.70681263013228, 0.16404792757812026, 0.44179116013620445], '645': [2.2388323604857887, 2.784026210466048, 0.1850730276433944, 0.31739303544051045], '646':[2.317657028721549, 2.949917446377885, 0.24850513527121498, 0.3676808102436452], '671': [2.630682474394549, 2.706364834017407, 0.16301316760562778, 0.44085146992520197], '675': [2.7067614833052813, 2.7173749384388346, 0.23870615585157873, 0.47708961405564254], '684': [2.6970360888981926, 2.8036701407791496, 0.23157910972791085, 0.5317115549334911], '680': [2.7200580191836536, 3.2662254613120227, 0.19824054093535326, 0.5540558678888127]}, 'demo_output': {}, 'gridlabd_output': {}, 'opendss_output': {'sourcebus': [0.17960357997560872, 0.5388107499674782, 0.16044213136336458, 0.6414216083753025], '650': [3.46173977571697e-05, 0.00027688611330264445, 0.00024463297015852746, 0.0011161493255213788], 'rg60': [0.0003803596442662037, 0.0006225803505498496, 0.0005903829452526287, 0.0014616392165030185], '633': [0.38047984831844595, 0.8729366035169337, 0.13271664569004354, 0.28972479926771977], '634': [0.010133922766079825, 0.020570453379602505, 0.006830751758597249, 0.012931935773494248], '671': [0.6108771018713602, 1.3265863413420522, 0.16093756369535386, 0.42423496513300524], '645': [0.4373080269407039, 0.8584390204064538, 0.18280284255143675, 0.32024566175842095], '646': [0.536560726260114, 0.9883607573047537, 0.24564544687076215, 0.36912074589189336], '692': [0.6119751654440972, 1.3274110796789444, 0.16196524206540175, 0.4251679482288616], '675': [0.7447836834016821, 1.3496142794655475, 0.20882248763406844, 0.46165856154276824], '611': [0.47109807838681994, 0.8597942885112269, 0.47109807838681994, 0.8597942885112269], '652': [0.5900525671135924, 0.8394468662430931, 0.5900525671135924, 0.8394468662430931], '670': [0.3852338293138269, 0.8975161336344963, 0.1039477429886314, 0.2879817616207214], '632': [0.2799093266146708, 0.6803831271514527, 0.07670340676752073, 0.21819919790776035], '680': [0.7346431542735055, 1.6877642140995293, 0.19615949605780691, 0.5372620670065573], '684': [0.7244901189090343, 1.397819420078607, 0.22833210323410577, 0.4698019455814719]}, 'synergi_output': {}}}) 
开发者ID:NREL,项目名称:ditto,代码行数:18,代码来源:create_excel.py

示例13: save_df_as_table

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def save_df_as_table(df, path,
                     format_str=SETTINGS.table_export_format,
                     transpose=SETTINGS.table_export_transpose,
                     confirm_overwrite=False):
    if confirm_overwrite and not user.check_and_confirm_overwrite(path):
        return
    if transpose:
        df = df.T
    if format_str == "excel":
        # requires xlwt and/or openpyxl to be installed
        with pd.ExcelWriter(path) as writer:
            df.to_excel(writer)
    else:
        getattr(df, "to_" + format_str)(path)
    logger.debug("{} table saved to: {}".format(
        format_str, path)) 
开发者ID:MichaelGrupp,项目名称:evo,代码行数:18,代码来源:pandas_bridge.py

示例14: test_to_excel

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def test_to_excel():
    modin_df = create_test_modin_dataframe()
    pandas_df = create_test_pandas_dataframe()

    TEST_EXCEL_DF_FILENAME = "test_df.xlsx"
    TEST_EXCEL_pandas_FILENAME = "test_pandas.xlsx"

    modin_writer = pandas.ExcelWriter(TEST_EXCEL_DF_FILENAME)
    pandas_writer = pandas.ExcelWriter(TEST_EXCEL_pandas_FILENAME)

    modin_df.to_excel(modin_writer)
    pandas_df.to_excel(pandas_writer)

    modin_writer.save()
    pandas_writer.save()

    assert assert_files_eq(TEST_EXCEL_DF_FILENAME, TEST_EXCEL_pandas_FILENAME)

    teardown_test_file(TEST_EXCEL_DF_FILENAME)
    teardown_test_file(TEST_EXCEL_pandas_FILENAME) 
开发者ID:modin-project,项目名称:modin,代码行数:22,代码来源:test_io.py

示例15: test_io_xlsx

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import ExcelWriter [as 别名]
def test_io_xlsx(test_df, meta_args):
    # add column to `meta`
    test_df.set_meta(['a', 'b'], 'string')

    # write to xlsx (direct file name and ExcelWriter, see bug report #300)
    file = 'testing_io_write_read.xlsx'
    for f in [file, pd.ExcelWriter(file)]:
        test_df.to_excel(f, **meta_args[0])
        if isinstance(f, pd.ExcelWriter):
            f.close()

        # read from xlsx
        import_df = IamDataFrame(file, **meta_args[1])

        # assert that IamDataFrame instances are equal and delete file
        assert_iamframe_equal(test_df, import_df)
        os.remove(file) 
开发者ID:IAMconsortium,项目名称:pyam,代码行数:19,代码来源:test_io.py


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