The website provides a comprehensive guide on using Java with Jupyter Notebooks, particularly focusing on importing and querying CSV data as Dataframes using Tablesaw, with practical examples including data from the UC Irvine Machine Learning Repository and AWS S3.
Abstract
The article is a detailed tutorial on manipulating CSV data using Java within Google Colab's Jupyter Notebook environment. It builds upon previous articles that introduced Java programming in Jupyter Notebooks and the use of 'Magics' for library import. The guide demonstrates how to download, import, and export CSV data as Dataframes with Tablesaw, a Java library for data manipulation. It also covers various file types supported by Tablesaw, such as Excel, JSON, and Parquet, and provides instructions on specifying column data types during import. Additionally, the article illustrates how to download files using Apache Commons IO FileUtils and how to import data from AWS S3 into a Dataframe. The tutorial aims to help readers get started with data processing in Java and encourages them to explore further with Tablesaw and other data processing tools in Java.
Opinions
The author assumes familiarity with concepts covered in previous articles, indicating a progressive learning curve for readers.
The article emphasizes the ease of working with Dataframes in Java, suggesting that Tablesaw is a user-friendly tool for data manipulation.
The author provides a positive outlook on using Java for data processing in Jupyter Notebooks, challenging the common perception that Python is the sole language for such tasks.
By including a template Jupyter Notebook and linking to a GitHub Gist, the author facilitates a hands-on approach to learning, encouraging readers to actively follow along with the tutorial.
The mention of the skewed distribution of the 'area' variable in the forest fires dataset implies the need for data transformation techniques, such as logarithmic scaling, to improve modeling outcomes.
The author expresses an open invitation for feedback and a willingness to engage with the community, indicating a collaborative approach to learning and development in the field of data science with Java.
Dataframes and CSV with Java on Jupyter
Some simple examples of how to download, import/export, & query CSV data as Dataframes using Java on Google Colab (Jupyter).
Introduction
In previous articles, I demonstrated how we can code with Java in Jupyter Notebooks on Google Colab, use ‘Magics’ to import libraries, and further got our feet wet working with Dataframes using Tablesaw.
In this article, the first of several in this series, we’ll go over some simple examples of how to download and import CSV data using Tablesaw, Google Colab, and a few relevant and handy libraries.
Creating Dataframes From Various File Types Using Tablesaw
Tablesaw provides us with numerous options for importing data into ‘Tables’, which is Tablesaw’s primary class for representing and working with Dataframes.
Options include:
CSV
FixedWidth
Excel
Parquet
JSON
JDBC
HTML
Stream → S3, HTTP(S), etc.
Getting Started
Copy the Jupyter Notebook & Load the Java Kernel
We’ll have to assume you are familiar with the concepts covered in the articles above. To speed things along, here is a template of a Jupyter Notebook on GitHub, including the steps needed to download and install the Java Kernel and load useful tools related to Tablesaw, compliments of the team behind Deep Java Learning.
NOTE: for a more detailed walk-through of the below steps. See either of the two previous articles linked above.
From Google Colab, open and create a copy of this notebook:
Afterward, you should see ‘forestfires.csv’ and ‘forestfires.names’ in your default work directory on Google Colab, as shown below.
Next, let’s open and preview the ‘forestfires.names’ file, which contains detailed description of the structure of the csv, the authors, how to cite use of this data, and some history behind the data.
The structure of the data described in this file is as follows:
Attributeinformation:
For more information, read [Cortez and Morais, 2007].
1. X - x-axis spatial coord. within the Montesinho park map: 1 to 92. Y - y-axis spatial coord. within the Montesinho park map: 2 to 93. month - month of the year: "jan" to "dec"4. day - day of the week: "mon" to "sun"5. FFMC - FFMC index from the FWI system: 18.7 to 96.206. DMC - DMC index from the FWI system: 1.1 to 291.37. DC - DC index from the FWI system: 7.9 to 860.68. ISI - ISI index from the FWI system: 0.0 to 56.109. temp - temperature in Celsius degrees: 2.2 to 33.3010. RH - relative humidity in %: 15.0 to 10011. wind - wind speed in km/h: 0.40 to 9.4012. rain - outside rain in mm/m2 : 0.0 to 6.413. area - the burned area of the forest (in ha): 0.00 to 1090.84
(this output variable is very skewed towards 0.0, thus it may make sense to model withthe logarithm transform).
Creating Tables from CSV Files
This next part is easy, provided you have a CSV file that conforms to one of several common formats, which may often not be the case, as we’ll see later.
This dataset provides daily updates on the volume of US job listings filtered by geography industry job family and role; normalized to pre-covid levels…
… Data is derived from online job listings tracked continuously, calculated daily and published nightly. On average data from 70% of all new US jobs are captured, and the dataset currently contains data from 3.3 million hiring organizations.
The documentation regarding the structure and description of this dataset can be found here.
As above, we’re going to download this data and import it into a Table using Tablesaw.
First, we’ll use our trusty Magic to import the necessary AWS SDK for Java.
%maven com.amazonaws:aws-java-sdk-s3:1.12.90
From the site where we found the Covid Job Impact data, we’ll need the S3 Bucket Name & Region.
The Bucket Name is greenwichhr-covidjobimpacts, and the Region is us-east-2. Because this is an ‘Open’ dataset, we don’t need any form of authentication, we just need a working S3 client.
Enter the following into a code block to first list out the objects in the bucket.
Next, let’s first identify one object to download. Let’s start with industry_job_family.csv.part_00000. Finally, we’ll download the object and import it into a table using CsvReadOptions.builder(InputStream stream){}.
Conclusion
That’s it! Well, that at least get’s you started, I hope. There’s quite a bit more to importing data, even just CSV, and I hope to go over some of those specifics in upcoming articles.
In the meantime, you can explore what Tablesaw has currently documented about importing data on their website here.
I’d love to hear back from anyone exploring how to use Java in the context of Notebooks (Jupyter, Zeppelin, etc.) and on the command line (JShell) for data processing using tools like Tablesaw. Shoot me a message, especially if you have published any material on Medium, and I’ll be happy to link to your content in the future, when relevant.
References
[Cortez and Morais, 2007] P. Cortez and A. Morais. A Data Mining Approach to Predict Forest Fires using Meteorological Data. In J. Neves, M. F. Santos and J. Machado Eds., New Trends in Artificial Intelligence, Proceedings of the 13th EPIA 2007 — Portuguese Conference on Artificial Intelligence, December, Guimarães, Portugal, pp. 512–523, 2007. APPIA, ISBN-13 978–989–95618–0–9. Available at: [Web Link]
Please consider signing up for a Medium membership with the above member Referral Link — Thank You!
Note from the Author
In addition to the material covered above, I’d love to hear back from anyone exploring how to use Java in the context of Notebooks (Jupyter, Zeppelin, etc.) and on the command line (JShell) for data processing and visualization using tools like Tablesaw.
Shoot me a message, especially if you have published any material on Medium, and I’ll be happy to link to your content in the future, when relevant.