Skip to main content

Read and write list of `pandas.DataFrame`s of tabular data from/to excel file.

Project description

xlsx2dfs

Easy loading from and writing to excel sheets to/from pandas DataFrames (and list of sheet_names).

Installation

pip install xlsx2dfs

Usage

from xlsx2dfs import xlsx2dfs, withNames, dfs2xlsx

# xlsx file path
fpath = "test.xlsx"

# read from it:
dfs, sheet_names = xlsx2dfs(fpath)

# write to it 
out_fpath = "out_test.xlsx"
dfs2xlsx(dfs, sheet_names=["sheet1", "sheet2", "sheet3"], out_fpath=out_fpath)

# or using `withNames` which allows alternate input of sheet_name and corresponding df
# `withNames("sheet1", dfs[0], "sheet2" dfs[1], "sheet3", dfs[2])` returns
# ([dfs[0], dfs[1], dfs[2]], ["sheet1", "sheet2", "sheet3"])
# thus (dfs, sheet_names). Using asterisk we can integrate them into the argument list
# of `dfs2xlsx`.
dfs2xlsx(*withNames("sheet1", dfs[0], "sheet2" dfs[1], "sheet3", dfs[2]), out_fpath)
# This makes especially sense when you have different data frames as results in your script
# and you want to save few lines of code which would be needed to bind them
# together into a list and name them.
# Instead, you can do the naming and binding to a list using `*withNames().
# This also enhances readability and is intuitive.
# e.g.
dfs2xlsx(*withNames("Temperatures", temperatures_df,
                    "Prediction", prediction_df,
                    "Original Data", orig_df), 
         "/path/to/output/file.xlsx")

document the version:

  • Linux: $ pip freeze | grep xlsx2dfs
  • Windows: c:\> pip freeze | findstr xlsx2dfs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xlsx2dfs-0.1.0.post6.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

xlsx2dfs-0.1.0.post6-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page