Book Image

Python Business Intelligence Cookbook

Book Image

Python Business Intelligence Cookbook

Overview of this book

The amount of data produced by businesses and devices is going nowhere but up. In this scenario, the major advantage of Python is that it's a general-purpose language and gives you a lot of flexibility in data structures. Python is an excellent tool for more specialized analysis tasks, and is powered with related libraries to process data streams, to visualize datasets, and to carry out scientific calculations. Using Python for business intelligence (BI) can help you solve tricky problems in one go. Rather than spending day after day scouring Internet forums for “how-to” information, here you’ll find more than 60 recipes that take you through the entire process of creating actionable intelligence from your raw data, no matter what shape or form it’s in. Within the first 30 minutes of opening this book, you’ll learn how to use the latest in Python and NoSQL databases to glean insights from data just waiting to be exploited. We’ll begin with a quick-fire introduction to Python for BI and show you what problems Python solves. From there, we move on to working with a predefined data set to extract data as per business requirements, using the Pandas library and MongoDB as our storage engine. Next, we will analyze data and perform transformations for BI with Python. Through this, you will gather insightful data that will help you make informed decisions for your business. The final part of the book will show you the most important task of BI—visualizing data by building stunning dashboards using Matplotlib, PyTables, and iPython Notebook.
Table of Contents (12 chapters)
Python Business Intelligence Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Importing an Excel file into MongoDB


MongoDB does not support the direct import of Excel files, so to do that, we will use a function built into Excel.

Getting ready

The mongoimport utility supports only JSON, CSV, and TSV files. Therefore, to get your data from Excel into MongoDB, the best option is to save it as a CSV file, and then use mongoimport to import it.

How to do it…

In Excel:

  1. Go to the File menu.

  2. Select Save As.

  3. Save the file in the Comma Separated Values (CSV) format.

After you perform the preceding steps, you can use the previous recipe to import the file.

If you think that's too easy though, you can import the Excel file into a Pandas DataFrame using read_excel, write the entire DataFrame to a CSV file using to_csv, and then import it using mongoimport. I highly recommend the first and much easier option.

How it works…

This recipe works almost exactly like our previous recipe for importing a CSV file; only here, we start with an Excel file, which we save as a CSV file.