Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Data> Data Analysis> Extending Excel with Python and R
Extending Excel with Python and R
Extending Excel with Python and R

Extending Excel with Python and R: Unlock the potential of analytics languages for advanced data manipulation and visualization

Arrow left icon
Profile Icon Steven SandersonProfile Icon Kun
Arrow right icon
$44.99
Full star iconFull star iconFull star iconFull star iconFull star icon5(5 Ratings)
PaperbackApr 2024344 pages1st Edition
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Steven SandersonProfile Icon Kun
Arrow right icon
$44.99
Full star iconFull star iconFull star iconFull star iconFull star icon5(5 Ratings)
PaperbackApr 2024344 pages1st Edition
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Table of content iconView table of contentsPreview book icon Preview Book

Extending Excel with Python and R

Reading Excel Spreadsheets

In the deep and wide landscape of data analysis, Excel stands tall and by your side as a trusted warrior, simplifying the process of organizing, calculating, and presenting information. Its intuitive interface and widespread usage have cemented its position as a staple in the business world. However, as the volume and complexity of data continue to grow exponentially, Excel’s capabilities may start to feel constrained. It is precisely at this point that the worlds of Excel, R, and Python converge. Extending Excel with R and Python invites you to embark on a truly transformative journey. This trip will show you the power of these programming languages as they synergize with Excel, expanding its horizons and empowering you to conquer data challenges with ease. In this book, we will delve into how to integrate Excel with R and Python, uncovering the hidden potential that lies beneath the surface and enabling you to extract valuable insights, automate processes, and unleash the true power ofdata analysis.

Microsoft Excel came to market in 1985 and has remained a popular spreadsheet software choice. Excel was originally known as MultiPlan. Microsoft Excel and databases in general share some similarities in terms of organizing and managing data, although they serve different purposes. Excel is a spreadsheet program that allows users to store and manipulate data in a tabular format. It consists of rows and columns, where each cell can contain text, numbers, or formulas. Similarly, a database is a structured collection of data stored in tables, consisting of rowsand columns.

Both Excel and databases provide a way to store and retrieve data. In Excel, you can enter data, perform calculations, and create charts and graphs. Similarly, databases store and manage large amounts of structured data and enable querying, sorting, and filtering. Excel and databases also support the concept of relationships. In Excel, you can link cells or ranges across different sheets, creating connections between data. Databases use relationships to link tables based on common fields, allowing you to retrieve related data frommultiple tables.

This chapter aims to familiarize you with reading Excel files into the R environment and performing some manipulation on them. Specifically, in this chapter, we’re going to cover the followingmain topics:

  • R packages forExcel manipulation
  • Reading Excel files to manipulatewith R
  • Reading multiple Excel sheets with a customR function
  • Python packages forExcel manipulation
  • Opening an Excel sheet from Python and readingthe data

Technical requirements

At the time of writing, we are usingthe following:

  • R 4.2.1
  • The RStudio 2023.03.1+446 “Cherry Blossom” releasefor Windows

For this chapter, you will need to install thefollowing packages:

  • readxl
  • openxlsx
  • xlsx

To run the Python code in this chapter, we will be usingthe following:

  • Python 3.11
  • pandas
  • openpyxl
  • Theiris.xlsx Excel file available in this book’sGitHub repository

While setting up a Python environment is outside the scope of this book, this is easy to do. The necessary packages can be installed by running thefollowing commands:

python -m pip install pandas==2.0.1python -m pip install openpyxl==3.1.2

Note that these commands have to be run from a terminal and not from within a Python script. They need to be run in the folder whererequirements.txt resides or a full path to therequirements.txt file has to be included.

This book’s GitHub repository also contains arequirements.txt file that you can use to install all dependencies. You can do this by running thefollowing command:

python -m pip install -r requirements.txt

This command installs all the packages that will be used in this chapter so that you don’t have to install them one by one. It also guarantees that the whole dependency tree (including the dependencies of the dependencies) will be the same as what this book’s authorshave used.

Alternatively, when using Jupyter Notebooks, you can use the followingmagic commands:

%pip install pandas==2.0.1%pip install openpyxl==3.1.2

There is a GitHub account for all of the code examples in this book located at this link:https://github.com/PacktPublishing/Extending-Excel-with-Python-and-R. Each chapter has it’s own folder, with the current one asChapter01.

Note

Technical requirements for Python throughout the book are conveniently compiled in therequirements.txt file, accessible on GitHub repository here,https://github.com/PacktPublishing/Extending-Excel-with-Python-and-R/blob/main/requirements.txt. Installing these dependencies will streamline your coding experience and ensure smooth progression through the book. Be sure to install them all before diving intothe exercises.

Working with R packages for Excel manipulation

There are several packages available both on CRAN and on GitHub that allow for reading and manipulation of Excel files. In this section, we are specifically going to focus on the packages:readxl,openxlsx, andxlsx to read Excel files. These three packages all have their own functions to read Excel files. These functions areas follows:

  • readxl::read_excel()
  • openxlsx::read.xlsx()
  • xlsx::read.xlsx()

Each function has a set of parameters and conventions to follow. Sincereadxl is part of thetidyverse collection of packages, it follows its conventions and returns atibble object upon reading the file. If you do not know what a tibble is, it is a modern version of R’sdata.frame, a sort of spreadsheet in the R environment. It is the building block of most analyses. Moving on toopenxlsx andxlsx, they both return a base Rdata.frame object, with the latter also able to return alist object. If you are wondering how this relates to manipulating an actual Excel file, I can explain. First, to manipulate something in R, the data must be in the R environment, so you cannot manipulate the file unless the data is read in. These packages have different functions for manipulating Excel or reading data in certain ways that allow for further analysis and or manipulation. It is important to note thatxlsx does require Java tobe installed.

As we transition from our exploration of R packages for Excel manipulation, we’ll turn our attention to the crucial task of effectively reading Excel files into R, thereby unlocking even more possibilities for data analysisand manipulation.

Reading Excel files to R

In this section, we are going to read data from Excel with a few different R libraries. We need to do this before we can even consider performing any type of manipulation or analysis on the data contained in the sheets of theExcel files.

As mentioned in the Technical requirements section, we are going to be using thereadxl,openxlsx, andxlsx packages to read datainto R.

Installing and loading libraries

In this section, we are going to install and load the necessary libraries if you do not yet have them. We are going to use theopenxlsx,xlsx,readxl, andreadxlsb libraries. To install and load them, run the followingcode block:

pkgs <- c("openxlsx", "xlsx", "readxl")install.packages(pkgs, dependencies = TRUE)lapply(pkgs, library, character.only = TRUE)

Thelapply() function in R is a versatile tool for applying a function to each element of a list, vector, orDataFrame. It takes two arguments,x andFUN, wherex is the list andFUN is the function that is applied to the listobject,x.

Now that the libraries have been installed, we can get to work. To do this, we are going to read a spreadsheet built from the Iris dataset that is built into base R. We are going to read the file with three different libraries, and then we are going to create a custom function to work with thereadxl library that will read all the sheets of an Excel file. We will call this theread_excel_sheets() function.

Let’s start reading the files. The first library we will use to open an Excel file isopenxlsx. To read the Excel file we are working with, you can run the code in thechapter1 folder of this book’s GitHub repository calledch1_create_iris_dataset.R Refer to the following screenshot to see how to read the fileinto R.

You will notice a variable calledf_pat. This is the path to where the Iris dataset was saved as an Excel file – forexample,C:/User/UserName/Documents/iris_data.xlsx:

Figure 1.1 – Using the openxlsx package to read the Excel file

Figure 1.1 – Using the openxlsx package to read the Excel file

The preceding screenshot shows how to read an Excel file. This example assumes that you have used thech1_create_iris_datase.R file to create the example Excel file. In reality, you can read in any Excel file that you would likeor need.

Now, we will perform the same type of operation, but this time with thexlsx library. Refer to the following screenshot, which uses the same methodology as with theopenxlsx package:

Figure 1.2 – Using the xlsx library and the read.xlsx() function to open the Excel file we’ve created

Figure 1.2 – Using the xlsx library and the read.xlsx() function to open the Excel file we’ve created

Finally, we will use thereadxl library, which is partofthe tidyverse:

Figure 1.3 – Using the readxl library and the read_excel() function to read the Excel file into memory

Figure 1.3 – Using the readxl library and the read_excel() function to read the Excel file into memory

In this section, we learned how to read in an Excel file with a few different packages. While these packages can do more than simply read in an Excel file, that is what we needed to focus on in this section. You should now be familiar with how to use thereadxl::read_excel(),xlsx::read.xlsx(), andopenxlsx::read.xlsx() functions.

Building upon our expertise in reading Excel files into R, we’ll now embark on the next phase of our journey: unraveling the secrets of efficiently extracting data from multiple sheets within anExcel file.

Reading multiple sheets with readxl and a custom function

In Excel, we often encounterworkbooks that have multiple sheets in them. These could be stats for different months of the year, table data that follows a specific format month over month, or some other period. The point is that we may want to read all the sheets in a file for one reason or another, and we should not call the read function from a particular package for each sheet. Instead, we should use the power of R to loop through thiswithpurrr.

Let’s build a customized function. To do this, we are going to load thereadxl function. If we have it already loaded, then this is not necessary; however, if it is already installed and you do not wish to load the library into memory, then you can call theexcel_sheets() function byusingreadxl::excel_sheets():

Figure 1.4 – Creating a function to read all the sheets into an Excel file at once – read_excel_sheets()

Figure 1.4 – Creating a function to read all the sheets into an Excel file at once – read_excel_sheets()

The new code can be broken downas follows:

 read_excel_sheets <- function(filename, single_tbl) {

This line defines a function calledread_excel_sheets that takes two arguments:filename (the name of the Excel file to be read) andsingle_tbl (a logical value indicating whether the function should return a single table or a listof tables).

Next, we have thefollowing line:

sheets <- readxl::excel_sheets(filename)

This line uses thereadxl package to extract the names of all the sheets in the Excel file specified byfilename. The sheet names are stored in thesheets variable.

Here’s thenext line:

if (single_tbl) {

This line starts anif statement that checks the value of thesingle_tbl argument.

Now, we havethe following:

x <- purrr::map_df(sheets, read_excel, path = filename)

Ifsingle_tbl isTRUE, this line uses thepurrr package’smap_df function to iterate over each sheet name insheets and read the corresponding sheet using theread_excel function from thereadxl package. The resultingDataFrame are combined into a single table, which is assigned to thex variable.

Now, we have thefollowing line:

} else {

This line indicates the start of theelse block of theif statement. Ifsingle_tbl isFALSE, the code in this block willbe executed.

Here’s thenext line:

 x <- purrr::map(sheets, ~ readxl::read_excel(filename, sheet = .x))

In this line, thepurrr package’smap function is used to iterate over each sheet name insheets. For each sheet, theread_excel function from thereadxl package is called to read the corresponding sheet from the Excel file specified byfilename. The resultingDataFrame are stored in a list assigned to thex variable.

Now, we havethe following:

 purrr::set_names(x, sheets)

This line uses theset_names function from thepurrr package to set the names of the elements in thex list to the sheet namesin sheets.

Finally, we have thefollowing line:

 x

This line returns the value ofx from the function, which will be either a single table (data.frame) ifsingle_tbl isTRUE, or a list of tables (data.frame) ifsingle_tblisFALSE.

In summary, theread_excel_sheets function takes an Excel filename and a logical value indicating whether to return a single table or a list of tables. It uses thereadxl package to extract the sheet names from the Excel file, and then reads the corresponding sheets either into a single table (ifsingle_tbl isTRUE) or into a list of tables (ifsingle_tbl isFALSE). The resulting data is returned as the output of the function. To see how this works, let’s look at thefollowing example.

We have a spreadsheet that has four tabs in it – one for each species in the famous Iris dataset and then one sheet callediris, which is thefull dataset.

As shown inFigure 1.5, theread_excel_sheets() function has read all four sheets of the Excel file. We can also see that the function has imported the sheets as a list object and has named each item in the list after the name of the corresponding tab in the Excel file. It is also important to note that the sheets must all have the same column names and structure for thisto work:

Figure 1.5 – Excel file read by read_excel_sheets()

Figure 1.5 – Excel file read by read_excel_sheets()

In this section, we learned how to write a function that will read all of the sheets in any Excel file. This function will also return them as a named item list, where the names are the names of the tabs in thefile itself.

Now that we have learned how to read Excel sheets in R, in the next section, we will cover Python, where we will revisit the same concepts but from the perspective of thePython language.

Python packages for Excel manipulation

In this section, we will explore how to read Excel spreadsheets using Python. One of the key aspects of working with Excel files in Python is having the right set of packages that provide the necessary functionality. In this section, we will discuss some commonly used Python packages for Excel manipulation and highlight their advantagesand considerations.

Python packages for Excel manipulation

When it comes to interacting with Excel files in Python, several packages offer a range of features and capabilities. These packages allow you to extract data from Excel files, manipulate the data, and write it back to Excel files. Let’s take a look at some popular Python packages forExcel manipulation.

pandas

pandas is a powerful data manipulation library that can read Excel files using theread_excel function. The advantage of usingpandas is that it provides aDataFrame object, which allows you to manipulate the data in a tabular form. This makes it easy to perform data analysis and manipulation.pandas excels in handling large datasets efficiently and provides flexible options for data filtering, transformation,and aggregation.

openpyxl

openpyxl is a widely used library specificallydesigned for working with Excel files. It provides a comprehensive set of features for reading and writing Excel spreadsheets, including support for various Excel file formats and compatibility with different versions of Excel. In addition,openpyxl allows fine-grained control over the structure and content of Excel files, enabling tasks such as accessing individual cells, creating new worksheets, andapplying formatting.

xlrd and xlwt

xlrd andxlwt are older libraries that are still in use for reading and writing Excel files, particularly with legacy formats such as.xls.xlrd enables reading data from Excel files, whilexlwt facilitates writing data to Excel files. These libraries are lightweight and straightforward to use, but they lack some of the advanced features provided bypandasandopenpyxl.

Considerations

When choosing a Python package for Excel manipulation, it’s essential to consider the specific requirements of your project. Here are a few factors to keepin mind:

  • Functionality: Evaluate the package’s capabilities and ensure it meets your needs for reading Excel files. Consider whether you require advanced data manipulation features or if a simpler packagewill suffice.
  • Performance: If you’re working with large datasets or need efficient processing, packages such aspandas, which have optimized algorithms, can offer significantperformance advantages.
  • Compatibility: Check the compatibility of the package with different Excel file formats and versions. Ensure that it supports the specific format you are working with to avoid anycompatibility issues.
  • Learning curve: Consider the learning curve associated with each package. Some packages, such aspandas, have a more extensive range of functionality, but they may require additional time and effortto master.

Each package offers unique features and has its strengths and weaknesses, allowing you to read Excel spreadsheets effectively in Python. For example, if you need to read and manipulate large amounts of data,pandas may be the better choice. However, if you need fine-grained control over the Excel file,openpyxl will likely fit yourneeds better.

Consider the specific requirements of your project, such as data size, functionality, and compatibility, to choose the most suitable package for your needs. In the following sections, we will delve deeper into how to utilize these packages to read and extract data from Excel filesusing Python.

Opening an Excel sheet from Python and reading the data

When working with Excel files in Python, it’s common to need to open a specific sheet and read the data into Python for further analysis. This can be achieved using popular libraries such aspandas andopenpyxl, as discussed in theprevious section.

You can most likely use other Python and package versions, but the code in this section has not been tested with anything other than what we’vestated here.

Using pandas

pandas is a powerful data manipulation library that simplifies the process of working with structured data, including Excel spreadsheets. To read an Excel sheet usingpandas, you can use theread_excel function. Let’s consider an example of using theiris_data.xlsx file with a sheetnamedsetosa:

import pandas as pd# Read the Excel filedf = pd.read_excel('iris_data.xlsx', sheet_name='setosa')# Display the first few rows of the DataFrameprint(df.head())

You will need to run this code either with the Python working directory set to the location where the Excel file is located, or you will need to provide the full path to the file in theread_excel() command:

Figure 1.6 – Using the pandas package to read the Excel file

Figure 1.6 – Using the pandas package to read the Excel file

In the preceding code snippet, we imported thepandas library and utilized theread_excel function to readsetosa from theiris_data.xlsx file. The resulting data is stored in apandasDataFrame, which provides a tabular representation of the data. By callinghead() on theDataFrame, we displayed the first few rows of the data, giving us aquick preview.

Using openpyxl

openpyxl is a powerful library for working with Excel files, offering more granular control over individual cells and sheets. To open an Excel sheet and access its data usingopenpyxl, we can utilize theload_workbook function. Please note thatopenpyxl cannot handle.xls files, only the more modern.xlsx and.xlsm versions.

Let’s consider an example of using theiris_data.xlsx file with a sheetnamedversicolor:

import openpyxlimport pandas as pd# Load the workbookwb = openpyxl.load_workbook('iris_data.xlsx')# Select the sheetsheet = wb['versicolor']# Extract the values (including header)sheet_data_raw = sheet.values# Separate the headers into a variableheader = next(sheet_data_raw)[0:]# Create a DataFrame based on the second and subsequent lines of data with the header as column namessheet_data = pd.DataFrame(sheet_data_raw, columns=header)print(sheet_data.head())

The preceding code results in thefollowing output:

Figure 1.7 – Using the openpyxl package to read the Excel file

Figure 1.7 – Using the openpyxl package to read the Excel file

In this code snippet, we import theload_workbook function from theopenpyxl library. Then, we load the workbook by providing theiris_data.xlsx filename. Next, we select the desired sheet by accessing it using its name – in this case, this isversicolor. Once we’ve done this, we read the raw data using thevalues property of the loaded sheet object. This is a generator and can be accessed via afor cycle or by converting it into a list or aDataFrame, for example. In this example, we have converted it into apandasDataFrame because it is the format that is the most comfortable to workwith later.

Bothpandas andopenpyxl offer valuable features for working with Excel files in Python. While pandas simplifies data manipulation with itsDataFrame structure,openpyxl provides more fine-grained control over individual cells and sheets. Depending on your specific requirements, you can choose the library that best suitsyour needs.

By mastering the techniques of opening Excel sheets and reading data into Python, you will be able to extract valuable insights from your Excel data, perform various data transformations, and prepare it for further analysis or visualization. These skills are essential for anyone seeking to leverage the power of Python and Excel in theirdata-driven workflows.

Reading in multiple sheets with Python (openpyxl and custom functions)

In many Excel files, it’s common to have multiple sheets containing different sets of data. Being able to read in multiple sheets and consolidate the data into a single data structure can be highly valuable for analysis and processing. In this section, we will explore how to achieve this using theopenpyxl library and acustom function.

The importance of reading multiple sheets

When working with complex Excel files, it’s not uncommon to encounter scenarios where related data is spread across different sheets. For example, you may have one sheet for sales data, another for customer information, and yet another for product inventory. By reading in multiple sheets and consolidating the data, you can gain a holistic view and perform acomprehensive analysis.

Let’s start by examining the basic steps involved in reading inmultiple sheets:

  1. Load the workbook: Before accessingthe sheets, we need to load the Excel workbook using theload_workbook function providedbyopenpyxl.
  2. Get the sheet names: We can obtain the names of all the sheets in the workbook using thesheetnames attribute. This allows us to identify the sheets we wantto read.
  3. Read data from each sheet: By iterating over the sheet names, we can access each sheet individually and read the data.Openpyxl provides methods such asiter_rows oriter_cols to traverse the cells of each sheet and retrieve thedesired data.
  4. Store the data: To consolidate the data from multiple sheets, we can use a suitable data structure, such as apandasDataFrame or a Python list. As we read the data from each sheet, we concatenate or merge it into the consolidateddata structure:
    • If the data in all sheets follows the same format (as is the case in the example used in this chapter), we can simply concatenatethe datasets
    • However, if the datasets have different structures because they describe different aspects of a dataset (for example, one sheet contains product information, the next contains customer data, and the third contains the sales of the products to the customers), then we can merge these datasets based on unique identifiers to create acomprehensive dataset

Using openpyxl to access sheets

openpyxl is a powerful library that allows us to interact with Excel files using Python. It provides a wide range of functionalities, including accessing and manipulating multiple sheets. Before we dive into the details, let’s take a moment to understand whyopenpyxl is a popular choice forthis task.

One of the primary advantages ofopenpyxl is its ability to handle various Excel file formats, such as.xlsx and.xlsm. This flexibility allows us to work with different versions of Excel files without compatibility issues. Additionally,openpyxl provides a straightforward and intuitive interface to access sheet data, making it easier for us to retrieve thedesired information.

Reading data from each sheet

To begin reading in multiple sheets, we need to load the Excel workbook using theload_workbook function provided byopenpyxl. This function takes the file path as input and returns a workbook object that represents the entireExcel file.

Once we have loaded the workbook, we can retrieve the names of all the sheets using the sheetnames attribute. This gives us a list of sheet names present in the Excel file. We can then iterate over these sheet names to read the data from eachsheet individually.

Retrieving sheet data with openpyxl

openpyxl provides variousmethods to access the data withina sheet.

Two commonly used methods areiter_rows anditer_cols. These methods allow us to iterate over the rows or columns of a sheet and retrieve thecell values.

Let’s have a look at howiter_rows canbe used:

# Assuming you are working with the first sheetsheet = wb['versicolor']# Iterate over rows and print raw valuesfor row in sheet.iter_rows(min_row=1, max_row=5, values_only=True):    print(row)

Similarly,iter_cols can be usedlike this:

# Iterate over columns and print raw valuesfor column in sheet.iter_cols(min_col=1, max_col=5, values_only=True):    print(column)

When usingiter_rows oriter_cols, we can specify whether we want to retrieve the cell values as raw values or as formatted values. Raw values give us the actual data stored in the cells, while formatted values include any formatting applied to the cells, such as date formatting ornumber formatting.

By iterating over the rows or columns of a sheet, we can retrieve the desired data and store it in a suitable data structure. One popular choice is to usepandasDataFrame, which provide a tabular representation of the data and offer convenient methods for data manipulationand analysis.

An alternative solution is using thevalues attribute of the sheet object. This provides a generator for all values in the sheet (much likeiter_rows anditer_cols do for rows and columns, respectively). While generators cannot be used directly to access the data, they can be used infor cycles to iterate over each value. Thepandas library’sDataFrame function also allows direct conversion from a suitable generator object toaDataFrame.

Combining data from multiple sheets

As we read the data from each sheet, we can store it in a list or dictionary, depending on our needs. Once we have retrieved the data from all the sheets, we can combine it into a single consolidated data structure. This step is crucial for further analysisand processing.

To combine the data, we can usepandasDataFrame. By creating individualDataFrame for each sheet’s data and then concatenating or merging them into a singleDataFrame, we can obtain a comprehensive dataset that includes all the information frommultiple sheets.

Custom function for reading multiple sheets

To simplify the process of reading in multiple sheetsand consolidating the data, we can create custom functions tailored to our specific requirements. These functions encapsulate the necessary steps and allow us to reuse thecode efficiently.

In our example, we define a function calledread_multiple_sheets that takes the file path as input. Inside the function, we load the workbook usingload_workbook and iterate over the sheet names retrieved with thesheets attribute.

For each sheet, we access it using the workbook object and retrieve the data using the custom read_single_sheet function. We then store the retrieved data in a list. Finally, we combine the data from all the sheets into a singlepandasDataFrame using the appropriate concatenation methodfrompandas.

By using these custom functions, we can easily read in multiple sheets from an Excel file and obtain a consolidated dataset that’s ready for analysis. The function provides a reusable and efficient solution, saving us time and effort in dealing with complexExcel files.

Customizing the code

The provided example is a starting point that you can customize based on your specific requirements. Here are a few considerations for customizingthe code:

  • Filtering columns: If you only need specific columns from each sheet, you can modify the code to extract only the desired columns during the data retrieval step. You can do this by using theiter_cols method instead of thevalues attribute and using a filtered list in afor cycle or by filtering the resultingpandasDataFrame object(s).
  • Handling missing data: If the sheets contain missing data, you can incorporate appropriate handling techniques, such as filling in missing values or excludingincomplete rows.
  • Applying transformations: Depending on the nature of your data, you might need to apply transformations or calculations to the consolidated dataset. The custom function can be expanded to accommodatethese transformations.

Remember, the goal is to tailor the code to suit your unique needs and ensure it aligns with your dataprocessing requirements.

By leveraging the powerofopenpyxl and creating custom functions, you can efficiently read in multiple sheets from Excel files, consolidate the data, and prepare it for further analysis. This capability enables you to unlock valuable insights from complex Excel files and leverage the full potential ofyour data.

Now, let’s dive into an example that demonstratesthis process:

from openpyxl import load_workbookimport pandas as pddef read_single_sheet(workbook, sheet_name):   # Load the sheet from the workbook    sheet = workbook[sheet_name]    # Read out the raaw data including headers    sheet_data_raw = sheet.values    # Separate the headers into a variable    columns = next(sheet_data_raw)[0:]    # Create a DataFrame based on the second and subsequent lines of data with the header as column names and return it    return pd.DataFrame(sheet_data_raw, columns=columns)def read_multiple_sheets(file_path):    # Load the workbook    workbook = load_workbook(file_path)    # Get a list of all sheet names in the workbook    sheet_names = workbook.sheetnames    # Cycle through the sheet names, load the data for each and concatenate them into a single DataFrame    return pd.concat([read_single_sheet(workbook=workbook, sheet_name=sheet_name) for sheet_name in sheet_names], ignore_index=True)# Define the file path and sheet namesfile_path = 'iris_data.xlsx' # adjust the path as needed# Read the data from multiple sheetsconsolidated_data = read_multiple_sheets(file_path)# Display the consolidated dataprint(consolidated_data.head())

Let’s have a look atthe results:

Figure 1.8 – Using the openxlsx package to read in the Excel file

Figure 1.8 – Using the openxlsx package to read in the Excel file

In the preceding code, we definetwo functions:

  • read_single_sheet: This reads the data from a single sheet into apandasDataFrame
  • read_multiple_sheets: This reads and concatenates the data from all sheets inthe workbook

Within theread_multiple_sheets function, we load the workbook usingload_workbook and iterate over the sheet names. For each sheet, we retrieve the data using theread_single_sheet helper function, which reads the data from a sheet and creates apandasDataFrame for each sheet’s data, with the header row used as column names. Finally, we usepd.concat to combine all theDataFrame into a singleconsolidatedDataFrame.

By utilizing these custom functions, we can easily read in multiple sheets from an Excel file and obtain a consolidated dataset. This allows us to perform various data manipulations, analyses, or visualizations on thecombined data.

Understanding how to handle multiple sheets efficiently enhances our ability to work with complex Excel files and extract valuable insights fromdiverse datasets.

Summary

In this chapter, we explored the process of importing data from Excel spreadsheets into our programming environments. For R users, we delved into the functionalities of libraries such asreadxl,xlsx, andopenxlsx, providing efficient solutions for extracting and manipulating data. We also introduced a custom function,read_excel_sheets, to streamline the process of extracting data from multiple sheets within Excel files. On the Python side, we discussed the essentialpandas andopenpyxl packages for Excel manipulation, demonstrating their features through practical examples. At this point, you should have a solid understanding of these tools and their capabilities for efficient Excel manipulation anddata analysis.

In the next chapter, we will learn how to write the resultsto Excel.

Left arrow icon

Page1 of 9

Right arrow icon
Download code iconDownload Code

Key benefits

  • Perform advanced data analysis and visualization techniques with R and Python on Excel data
  • Use exploratory data analysis and pivot table analysis for deeper insights into your data
  • Integrate R and Python code directly into Excel using VBA or API endpoints
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

– Extending Excel with Python and R is a game changer resource written by experts Steven Sanderson, the author of the healthyverse suite of R packages, and David Kun, co-founder of Functional Analytics. – This comprehensive guide transforms the way you work with spreadsheet-based data by integrating Python and R with Excel to automate tasks, execute statistical analysis, and create powerful visualizations. – Working through the chapters, you’ll find out how to perform exploratory data analysis, time series analysis, and even integrate APIs for maximum efficiency. – Both beginners and experts will get everything you need to unlock Excel's full potential and take your data analysis skills to the next level. – By the end of this book, you’ll be able to import data from Excel, manipulate it in R or Python, and perform the data analysis tasks in your preferred framework while pushing the results back to Excel for sharing with others as needed.

Who is this book for?

– If you’re a data analyst or data scientist, or a quants, actuaries, or data practitioner looking to enhance your Excel skills and expand your data analysis capabilities with R and Python, this book is for you. – The comprehensive approach to the topics covered makes it suitable for both beginners and intermediate learners. – A basic understanding of Excel, Python, and R is all you need to get started.

What you will learn

  • Read and write Excel files with R and Python libraries
  • Automate Excel tasks with R and Python scripts
  • Use R and Python to execute Excel VBA macros
  • Format Excel sheets using R and Python packages
  • Create graphs with ggplot2 and Matplotlib in Excel
  • Analyze Excel data with statistical methods and time series analysis
  • Explore various methods to call R and Python functions from Excel
Estimated delivery feeDeliver to Ecuador

Standard delivery10 - 13 business days

$19.95

Premium delivery3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Apr 30, 2024
Length:344 pages
Edition :1st
Language :English
ISBN-13 :9781804610695
Category :
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Estimated delivery feeDeliver to Ecuador

Standard delivery10 - 13 business days

$19.95

Premium delivery3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date :Apr 30, 2024
Length:344 pages
Edition :1st
Language :English
ISBN-13 :9781804610695
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
$199.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts
$279.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts

Frequently bought together


Building Interactive Dashboards in Microsoft 365 Excel
Building Interactive Dashboards in Microsoft 365 Excel
Read more
Feb 2024420 pages
Full star icon4 (3)
eBook
eBook
$9.99$24.99
$29.99
Extending Excel with Python and R
Extending Excel with Python and R
Read more
Apr 2024344 pages
Full star icon5 (5)
eBook
eBook
$9.99$35.99
$44.99
Stars icon
Total$74.98
Building Interactive Dashboards in Microsoft 365 Excel
$29.99
Extending Excel with Python and R
$44.99
Total$74.98Stars icon
Buy 2+ to unlock$7.99 prices - master what's next.
SHOP NOW

Table of Contents

19 Chapters
Part 1:The Basics – Reading and Writing Excel Files from R and PythonChevron down iconChevron up icon
Part 1:The Basics – Reading and Writing Excel Files from R and Python
Chapter 1: Reading Excel SpreadsheetsChevron down iconChevron up icon
Chapter 1: Reading Excel Spreadsheets
Technical requirements
Working with R packages for Excel manipulation
Reading Excel files to R
Reading multiple sheets with readxl and a custom function
Python packages for Excel manipulation
Opening an Excel sheet from Python and reading the data
Reading in multiple sheets with Python (openpyxl and custom functions)
Summary
Chapter 2: Writing Excel SpreadsheetsChevron down iconChevron up icon
Chapter 2: Writing Excel Spreadsheets
Technical requirements
Packages to write into Excel files
Creating and manipulating Excel sheets using Python
Keeping it simple – exporting data to Excel with pandas
Advanced mode – openpyxl for Excel manipulation
Choosing between openpyxl and pandas
Other alternatives
Summary
Chapter 3: Executing VBA Code from R and PythonChevron down iconChevron up icon
Chapter 3: Executing VBA Code from R and Python
Technical requirements
Installing and explaining the RDCOMClient R library
Executing sample VBA with RDCOMClient
Integrating VBA with Python using pywin32
Automating Excel tasks
Summary
Chapter 4: Automating Further – Task Scheduling and EmailChevron down iconChevron up icon
Chapter 4: Automating Further – Task Scheduling and Email
Technical requirements
Installing and understanding the tasksheduleR library
RDCOMClient for Outlook
Using the Microsoft365R and blastula packages
Scheduling Python scripts
Email notifications and automation with Python
Summary
Part 2: Making It Pretty – Formatting, Graphs, and MoreChevron down iconChevron up icon
Part 2: Making It Pretty – Formatting, Graphs, and More
Chapter 5: Formatting Your Excel SheetChevron down iconChevron up icon
Chapter 5: Formatting Your Excel Sheet
Technical requirements
Installing and using styledTables in R
Advanced options for formatting with Python
Summary
Chapter 6: Inserting ggplot2/matplotlib GraphsChevron down iconChevron up icon
Chapter 6: Inserting ggplot2/matplotlib Graphs
Technical requirements
Some basics
Enhancing your Excel reports with plotnine2, matplotlib, and plotly graphs
Enhancing Excel reports with visualizations
An introduction to data visualization libraries
Creating graphs with plotnine (Python’s ggplot2)
Other visualization libraries
Embedding visualizations into Excel
Summary
Chapter 7: Pivot Tables and Summary TablesChevron down iconChevron up icon
Chapter 7: Pivot Tables and Summary Tables
Technical requirements
Making a table with the Base R xtabs function
Making a table with the gt package
Creating pivot tables with tidyquant
Creating and managing pivot tables in Python with win32com and pypiwin32
Creating pivot tables with Python: the basics
Summary
Part 3: EDA, Statistical Analysis, and Time Series AnalysisChevron down iconChevron up icon
Part 3: EDA, Statistical Analysis, and Time Series Analysis
Chapter 8: Exploratory Data Analysis with R and PythonChevron down iconChevron up icon
Chapter 8: Exploratory Data Analysis with R and Python
Technical requirements
Understanding data with skimr
Using the GGally package in R
Using the DataExplorer package
Getting started with EDA for Python
Data cleaning in Python for Excel data
Performing EDA in Python
Summary
Chapter 9: Statistical Analysis: Linear and Logistic RegressionChevron down iconChevron up icon
Chapter 9: Statistical Analysis: Linear and Logistic Regression
Technical requirements
Linear regression
Logistic regression
Performing linear regression in R
Performing logistic regression in R
Performing linear regression in Python using Excel data
Logistic regression in Python using Excel data
Summary
Chapter 10: Time Series Analysis: Statistics, Plots, and ForecastingChevron down iconChevron up icon
Chapter 10: Time Series Analysis: Statistics, Plots, and Forecasting
Technical requirements
Generating random time series objects in R
Time series plotting
Auto ARIMA modeling with healthyR.ts
Creating a Brownian motion with healthyR.ts
Time series analysis in Python – statistics, plots, and forecasting
Time series plotting – basic plots and ACF/PACF plots
Time series statistics and statistical forecasting
Understanding predictive modeling approaches
Time series forecasting with deep learning – LSTM
Summary
Part 4: The Other Way Around – Calling R and Python from ExcelChevron down iconChevron up icon
Part 4: The Other Way Around – Calling R and Python from Excel
Chapter 11: Calling R/Python Locally from Excel Directly or via an APIChevron down iconChevron up icon
Chapter 11: Calling R/Python Locally from Excel Directly or via an API
Technical requirements
Calling R and Python from Excel locally
Why you would want to call R/Python from Excel locally
Setting up an environment
Calling R/Python directly from Excel
Calling Python from Excel using xlwings
Calling R and Python from Excel via an API
An introduction to APIs
Open source solutions for exposing R as API endpoints
Open-source solutions for exposing Python as an API endpoint
Calling APIs from Excel VBA
Summary
Part 5: Data Analysis and Visualization with R and Python for Excel Data – A Case StudyChevron down iconChevron up icon
Part 5: Data Analysis and Visualization with R and Python for Excel Data – A Case Study
Chapter 12: Data Analysis and Visualization with R and Python in Excel – A Case StudyChevron down iconChevron up icon
Chapter 12: Data Analysis and Visualization with R and Python in Excel – A Case Study
Technical requirements
Getting visualizations with R
Performing a simple ML model with R
Getting visualizations with Python
Performing a simple ML model with Python
IndexChevron down iconChevron up icon
Index
Why subscribe?
Other Books You May EnjoyChevron down iconChevron up icon
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book

Recommendations for you

Left arrow icon
LLM Engineer's Handbook
LLM Engineer's Handbook
Read more
Oct 2024522 pages
Full star icon4.9 (27)
eBook
eBook
$9.99$47.99
$59.99
Getting Started with Tableau 2018.x
Getting Started with Tableau 2018.x
Read more
Sep 2018396 pages
Full star icon4 (3)
eBook
eBook
$9.99$43.99
$54.99
Python for Algorithmic Trading Cookbook
Python for Algorithmic Trading Cookbook
Read more
Aug 2024406 pages
Full star icon4.3 (20)
eBook
eBook
$9.99$47.99
$59.99
RAG-Driven Generative AI
RAG-Driven Generative AI
Read more
Sep 2024338 pages
Full star icon4.3 (16)
eBook
eBook
$9.99$35.99
$43.99
Machine Learning with PyTorch and Scikit-Learn
Machine Learning with PyTorch and Scikit-Learn
Read more
Feb 2022774 pages
Full star icon4.4 (87)
eBook
eBook
$9.99$43.99
$54.99
$79.99
Building LLM Powered Applications
Building LLM Powered Applications
Read more
May 2024342 pages
Full star icon4.2 (21)
eBook
eBook
$9.99$39.99
$49.99
Python Machine Learning By Example
Python Machine Learning By Example
Read more
Jul 2024526 pages
Full star icon4.3 (25)
eBook
eBook
$9.99$36.99
$45.99
AI Product Manager's Handbook
AI Product Manager's Handbook
Read more
Nov 2024488 pages
eBook
eBook
$9.99$31.99
$39.99
Right arrow icon

Customer reviews

Rating distribution
Full star iconFull star iconFull star iconFull star iconFull star icon5
(5 Ratings)
5 star100%
4 star0%
3 star0%
2 star0%
1 star0%
Amazon CustomerJun 17, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
### Exciting Book Review for Amazon 📊📈**Extending Excel with Python and R** by Steven Sanderson and David Kun is a game-changer! This incredible guide shows you how to integrate Python and R with Excel, automating tasks, performing advanced analyses, and creating stunning visualizations. Perfect for data enthusiasts, it covers everything from VBA macros to time series forecasting. Elevate your data skills and make Excel even more powerful. Highly recommended! 📚✨
Amazon Verified reviewAmazon
MaximJun 17, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
I am a Stats major. During my Senior year I took lots of R, Python and Advanced Excel classes. This book covers most of the things that I learned in college and provides code examples that you can use if you want to practice Data Analysis in Python. Great resource if you want to learn Data Science and Data Automation at your own pace.
Amazon Verified reviewAmazon
Taylor BalfanzJun 13, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
This is a must-read for any data enthusiast or professional seeking to enhance their analytical capabilities. This book seamlessly bridges the gap between Excel and the powerful programming languages Python and R.The book is well-structured, guiding the reader through the integration of Python and R with Excel step-by-step. Each chapter builds on the previous one, ensuring a solid understanding of the material. The practical examples and real-world case studies included in the book are particularly beneficial, as they illustrate the application of the concepts in a tangible way.Another noteworthy aspect of this book is its comprehensive coverage. It not only covers the basics but also delves into advanced topics, ensuring that readers gain a thorough understanding of how to leverage Python and R to extend Excel’s functionality. From automating repetitive tasks to performing sophisticated data analysis, the book equips readers with the knowledge needed to effectively increase their data analysis capabilities.
Amazon Verified reviewAmazon
GustavoMay 15, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
The book is very complete and takes you from very basic tasks like loading data from excel sheets to Python and R until more complex ones, such as VBA coding and automation.I especially liked the chapter about Time Series.Good book to Excel users to get started with programming languages.
Amazon Verified reviewAmazon
JayJul 27, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
I did pick this without thinking too much. I am pleasantly surprised by the content in here. I did think people might wonder why do you need Excel if you know Python and R, right? Well, my perspective was in 90% of jobs around the world, excel is going to be go to for majority of folks, that's how you submit reports to management or share stuff with other teams, and knowing to connect R and Python to do the analysis as a plugin to Excel can help a lot! Was surprised how much of the complex excel stuff you can automate easily with Python and R. Helped a ton with automating some of the stuff I never thought about previously. Great read!
Amazon Verified reviewAmazon

People who bought this also bought

Left arrow icon
Causal Inference and Discovery in Python
Causal Inference and Discovery in Python
Read more
May 2023466 pages
Full star icon4.5 (47)
eBook
eBook
$9.99$43.99
$53.99
Generative AI with LangChain
Generative AI with LangChain
Read more
Dec 2023376 pages
Full star icon4.1 (33)
eBook
eBook
$9.99$63.99
$79.99
Modern Generative AI with ChatGPT and OpenAI Models
Modern Generative AI with ChatGPT and OpenAI Models
Read more
May 2023286 pages
Full star icon4.1 (30)
eBook
eBook
$9.99$39.99
$49.99
Deep Learning with TensorFlow and Keras – 3rd edition
Deep Learning with TensorFlow and Keras – 3rd edition
Read more
Oct 2022698 pages
Full star icon4.5 (44)
eBook
eBook
$9.99$39.99
$49.99
Machine Learning Engineering  with Python
Machine Learning Engineering with Python
Read more
Aug 2023462 pages
Full star icon4.6 (37)
eBook
eBook
$9.99$39.99
$49.99
Right arrow icon

About the authors

Left arrow icon
Profile icon Steven Sanderson
Steven Sanderson
LinkedIn iconGithub icon
Steven Sanderson, MPH, is an applications manager for the patient accounts department at Stony Brook Medicine. He received his bachelor's degree in economics and his master's in public health from Stony Brook University. He has worked in healthcare in some capacity for just shy of 20 years. He is the author and maintainer of the healthyverse set of R packages. He likes to read material related to social and labor economics and has recently turned his efforts back to his guitar with the hope that his kids will follow suit as a hobby they can enjoy together.
Read more
See other products by Steven Sanderson
Profile icon Kun
Kun
LinkedIn icon
David Kun is a mathematician and actuary who has always worked in the gray zone between quantitative teams and ICT, aiming to build a bridge. He is a co-founder and director of Functional Analytics and the creator of the ownR Infinity platform. As a data scientist, he also uses ownR for his daily work. His projects include time series analysis for demand forecasting, computer vision for design automation, and visualization.
Read more
See other products by Kun
Right arrow icon
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order?Chevron down iconChevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge?Chevron down iconChevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order?Chevron down iconChevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries:www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges?Chevron down iconChevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live inMexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live inTurkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order?Chevron down iconChevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy?Chevron down iconChevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged?Chevron down iconChevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use?Chevron down iconChevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela

Create a Free Account To Continue Reading

Modal Close icon
OR
    First name is required.
    Last name is required.

The Password should contain at least :

  • 8 characters
  • 1 uppercase
  • 1 number
Notify me about special offers, personalized product recommendations, and learning tips By signing up for the free trial you will receive emails related to this service, you can unsubscribe at any time
By clicking ‘Create Account’, you are agreeing to ourPrivacy Policy andTerms & Conditions
Already have an account? SIGN IN

Sign in to activate your 7-day free access

Modal Close icon
OR
By redeeming the free trial you will receive emails related to this service, you can unsubscribe at any time.

[8]ページ先頭

©2009-2025 Movatter.jp