Spring Boot集成tablesaw插件快速入门Demo

news2024/7/4 5:39:37

1 什么是tablesaw?

Tablesaw是一款Java的数据可视化库,主要包括两部分:

  • 数据解析库,主要用于加载数据,对数据进行操作(转化,过滤,汇总等),类比Python中的Pandas库;

  • 数据可视化库,将目标数据转化为可视化的图表,类比Python中的Matplotlib库。

与Pandas不同的是,Tablesaw中的表格以列(Column)为基本单位,因此大部分操作都是基于列进行的。当然也包括部分对行操作的函数,但是功能比较有限

1.1 tablesaw目录说明

  1. aggregate:maven 的项目父级项目,主要定义项目打包的配置。

  2. beakerx:tablesaw 库的注册中心,主要注册表和列。

  3. core:tablesaw 库的核心代码,主要是数据的加工处理操作:数据的追加,排序,分组,查询等。

  4. data:项目测试数据目录。

  5. docs:项目 MarkDown 文档目录。

  6. docs-src:项目文档源码目录,主要作用是生成 MarkDown 文档。

  7. excel:解析 excel 文件数据的子项目。

  8. html:解析 html 文件数据的子项目。

  9. json:解析 json 文件数据的子项目。

  10. jsplot:数据可视化的子项目,主要作用加载数据生成可视化图表。

  11. saw:tablesaw 读写图表数据的子项目。

2 环境准备

2.1 数据库安装

数据库安装这里不做详细阐述,小伙伴们可自行安装,在docker环境下可执行:

docker run --name docker-mysql-5.7 -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:5.7

2.2 数据库表初始化


create database springboot_demo;
create table user_info
(
user_id     varchar(64)          not null primary key,
username    varchar(100)         null ,
age         int(3)               null ,
gender      tinyint(1)           null ,
remark      varchar(255)         null ,
create_time datetime             null ,
create_id   varchar(64)          null ,
update_time datetime             null ,
update_id   varchar(64)          null ,
enabled     tinyint(1) default 1 null
);
INSERT INTO springboot_demo.user_info
(user_id, username, age, gender, remark, create_time, create_id, update_time, update_id, enabled)
VALUES('1', '1', 1, 1, '1', NULL, '1', NULL, NULL, 1);

3 代码demo

3.1 完成目标

利用tablesaw加工和处理二维数据,并且可视化

3.2 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot-demo</artifactId>
        <groupId>com.wkf</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tablesaw</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>tech.tablesaw</groupId>
            <artifactId>tablesaw-core</artifactId>
            <version>0.43.1</version>
        </dependency>
        <dependency>
            <groupId>tech.tablesaw</groupId>
            <artifactId>tablesaw-jsplot</artifactId>
            <version>0.43.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.29</version>
        </dependency>
    </dependencies>
</project>

3.3 application.yaml

server:
  port: 8088
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:mysql://127.0.0.1:3305/springboot_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 123456

3.4 读取csv数据

    @Before
    public void before() {
        log.info("init some data");
        tornadoes = Table.read().csv("D:/gitProject/springboot-demo/tablesaw/src/main/resources/data/tornadoes_1950-2014.csv");
    }

3.5 打印列名

    @Test
    public void columnNames() {
        System.out.println(tornadoes.columnNames());
    }

运行效果:

在这里插入图片描述

3.6 查看shape

    @Test
    public void shape() {
        System.out.println(tornadoes.shape());
    }

运行效果:

在这里插入图片描述

3.7 查看表结构

    @Test
    public void structure() {
        System.out.println(tornadoes.structure().printAll());
    }

运行效果:

在这里插入图片描述

3.8 查看数据

    @Test
    public void show() {
        System.out.println(tornadoes);
    }

运行效果:

在这里插入图片描述

3.9 表结构过滤

    @Test
    public void structurefilter() {
        System.out.println( tornadoes
                .structure()
                .where(tornadoes.structure().stringColumn("Column Type").isEqualTo("DOUBLE")));

    }

运行效果:

在这里插入图片描述

3.10 预览数据

	@Test
    public void previewdata() {
        System.out.println(tornadoes.first(3));
    }

运行效果:

在这里插入图片描述

3.11 列操作

    @Test
    public void ColumnOperate() {
        StringColumn month = tornadoes.dateColumn("Date").month();
        tornadoes.addColumns(month);
        System.out.println(tornadoes.first(3));
        tornadoes.removeColumns("State No");
        System.out.println(tornadoes.first(3));

    }

运行效果:

在这里插入图片描述

3.12 排序

    @Test
    public void sort() {
        tornadoes.sortOn("-Fatalities");
        System.out.println(tornadoes.first(20));
    }

运行效果:

在这里插入图片描述

3.13 summary

    @Test
    public void summary() {
        System.out.println( tornadoes.column("Fatalities").summary().print());
    }

运行效果:

在这里插入图片描述

3.14 数据过滤

    @Test
    public void filter() {
        Table result = tornadoes.where(tornadoes.intColumn("Fatalities").isGreaterThan(0));
        result = tornadoes.where(result.dateColumn("Date").isInApril());
        result =
                tornadoes.where(
                        result
                                .intColumn("Width")
                                .isGreaterThan(300) // 300 yards
                                .or(result.doubleColumn("Length").isGreaterThan(10))); // 10 miles

        result = result.select("State", "Date");
        System.out.println(result);
    }

运行效果:

在这里插入图片描述

3.15 写入文件

    @Test
    public void write() {
        tornadoes.write().csv("rev_tornadoes_1950-2014-test.csv");
    }

3.16 从mysql读取数据

    @Resource
    private JdbcTemplate jdbcTemplate;
    
    @Test
    public void dataFromMySql() {
        Table table = jdbcTemplate.query("SELECT  user_id,username,age from user_info", resultSet -> {
            return Table.read().db(resultSet);
        });
        System.out.println(table);
    }

运行效果:

在这里插入图片描述

3.17 数据可视化

package com.wkf.tablesaw;

import tech.tablesaw.api.Table;
import tech.tablesaw.plotly.Plot;
import tech.tablesaw.plotly.api.BubblePlot;
import tech.tablesaw.plotly.components.Figure;

import java.io.IOException;

/**
 * @author wuKeFan
 * @date 2024-06-13 09:57:07
 */
public class BubbleExample {

    public static void main(String[] args) throws IOException {

        Table wines = Table.read().csv("D:/gitProject/springboot-demo/tablesaw/src/main/resources/data/tornadoes_1950-2014.csv");

        Table champagne =
                wines.where(
                        wines
                                .stringColumn("wine type")
                                .isEqualTo("Champagne & Sparkling")
                                .and(wines.stringColumn("region").isEqualTo("California")));

        Figure figure =
                BubblePlot.create(
                        "Average retail price for champagnes by year and rating",
                        champagne, // table namex
                        "highest pro score", // x variable column name
                        "year", // y variable column name
                        "Mean Retail" // bubble size
                );

        Plot.show(figure);
    }

}

结果如下图:

在这里插入图片描述

4 代码仓库

https://github.com/363153421/springboot-demo/tree/master/tablesaw

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1818194.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

tp6+swoole+mysql+nginx+redis高并发优化

1.服务器 IDC机房提供的物理机&#xff1a;单机 40核&#xff0c;64G内存&#xff0c;带宽100M&#xff0c; 2.redis 7.2配置 timeout600 #空闲连接超时时间,0表示不断开 maxclients100000 #最大连接数 3.Mysql 5.7配置&#xff0c;按宝塔16-32G优化方案并调整&#xff1a;…

springboot+shiro+jwt 兼容session和token

最近和别的软件集成项目&#xff0c;需要提供给别人接口来进行数据传输&#xff0c;发现给他token后并不能访问我的接口&#xff0c;拿postman试了下还真是不行。检查代码发现项目的shiro配置是通过session会话来校验信息的 &#xff0c;我之前一直是前后端自己写&#xff0c;用…

总结了几类Midjourney制作网站风格设计的关键词和方法

第一种&#xff1a;根据简单的图生成你想要的设计风格Demo 我们拿MJ的一款网站风格分析 类似你只有一款产品图或者是风格框架图&#xff0c;JPG或者PNG透明格式都OK&#xff0c;来生成网站首页设计风格。 1&#xff1a;你先上传产品图到MJ 2&#xff1a;打开命令行&#xff…

Linux Radix tree简介

文章目录 前言一、Radix tree简介二、Operations2.1 Lookup2.2 Insertion2.3 Deletion 三、Linux内核API3.1 初始化3.2 radix_tree_insert/delete3.3 radix_tree_preload3.4 radix_tree_lookup3.5 radix_tree_tag_set3.6 radix_tree_tagged 四、address_space4.1 简介4.2 相应数…

浅谈配置元件之HTTP请求默认值

浅谈配置元件之HTTP请求默认值 在进行HTTP请求的测试计划设计时&#xff0c;"HTTP请求默认值"配置元件扮演着极其重要的角色&#xff0c;它能够简化测试计划的设置&#xff0c;提高测试效率。本问将详细介绍如何使用JMeter中的“HTTP请求默认值”配置元件。 HTTP请求…

每日一题——Python实现PAT甲级1116 Come on! Let‘s C(举一反三+思想解读+逐步优化)五千字好文

一个认为一切根源都是“自己不够强”的INTJ 个人主页&#xff1a;用哲学编程-CSDN博客专栏&#xff1a;每日一题——举一反三Python编程学习Python内置函数 Python-3.12.0文档解读 目录 我的写法 代码点评 时间复杂度分析 空间复杂度分析 总结 我要更强 优化思路 优化…

四川古力未来科技抖音小店可靠购物新体验

在当下数字化浪潮席卷的时代&#xff0c;抖音小店作为电商领域的新兴力量&#xff0c;正以其独特的魅力吸引着越来越多的消费者。而四川古力未来科技抖音小店&#xff0c;作为其中的佼佼者&#xff0c;其可靠性与否自然成为了广大消费者关注的焦点。本文将从多个角度对四川古力…

Pytorch环境深度学习环境

Pytorch环境深度学习环境 1、安装minicoda 下载地址&#xff1a;Miniconda — miniconda documentation 设置环境变量&#xff1a; 安装路径\Miniconda3 安装路径\Miniconda3\Scripts安装路径\Miniconda3\Library\bin 测试&#xff1a;打开cmd&#xff0c;输入conda测试指令…

Java的核心类库

引言 在Java编程中&#xff0c;熟练掌握常用类与对象操作是开发的基础。Java的核心类库提供了丰富的功能&#xff0c;可以帮助开发者高效地处理各种编程任务。本文将详细介绍Java字符串操作、集合框架、日期与时间处理等内容&#xff0c;并通过图表和表格进行总结与示范。 字符…

神经网络 torch.nn---nn.RNN()

torch.nn - PyTorch中文文档 (pytorch-cn.readthedocs.io) RNN — PyTorch 2.3 documentation torch.nn---nn.RNN() nn.RNN(input_sizeinput_x,hidden_sizehidden_num,num_layers1,nonlinearitytanh, #默认tanhbiasTrue, #默认是Truebatch_firstFalse,dropout0,bidirection…

遥控器无法点击AOSP Settings 的管理存储按钮 MANAGE STORAGE

前言 这里是遇到了MANAGE STORAGE的按钮使用遥控器移动的时候无法聚焦到这个按钮&#xff0c;自然也就无法点击。它只能聚焦到这一整个整体&#xff0c;因此我就设置当点击到这一整个整体时&#xff0c;就相应MANAGE STORAGE按钮的点击事件。 图片 代码 packages/apps/Setti…

极限存在的条件

极限存在的条件 在左极限与又极限相关的内容中我们知道极限&#xff08;也叫双侧极限&#xff09;存在的充分必要条件是左右极限都存在且相等&#xff0c;否则极限不存在。所以这里要来详细的探讨一下在什么情况下函数会不存在极限。 1. 函数 f ( x ) 1 x f(x)\frac{1}{x} …

知识分享|个人查询大数据信用有哪些好处?

在当今数字化时代&#xff0c;个人信用评估已经成为金融、购物、租房等各个方面的关键因素。大数据技术的兴起为个人信用查询带来了新的可能性和好处。下面将探讨个人查询大数据信用的益处。 首先&#xff0c;个人查询大数据信用可以全面了解自己的信用状况 通过查询大数据信用…

46.Python-web框架-Django - 多语言配置

目录 1.Django 多语言基础知识 1.1什么是Django国际化和本地化&#xff1f; 1.2Django LANGUAGE_CODE 1.3关于languages 1.4RequestContext对象针对翻译的变量 2.windows系统下的依赖 3.django多语言配置 3.1settings.py配置 引用gettext_lazy 配置多语言中间件&#x…

白酒:茅台镇白酒的品鉴课程与文化学习

茅台镇&#xff0c;这个位于中国贵州省的美丽小镇&#xff0c;以其与众不同的自然环境和杰出的酿酒工艺&#xff0c;成为了世界著名的白酒产区。作为茅台镇的杰出代表&#xff0c;云仓酒庄豪迈白酒不仅在国内享有盛誉&#xff0c;在国际市场上也备受瞩目。为了更好地推广中国白…

产品经理研读:Agent的九种设计模式(图解+代码)

引言 上周五我在一个特工宇宙的社群里做了一次分享&#xff0c;题目是《从 YC 项目看 AI 趋势以及 AI agent 开发工具类产品该如何设计》&#xff0c;收到了大家不错的反馈&#xff0c;不过回看视频后还是发现不少可以提升的地方&#xff0c;感兴趣的朋友公众号回复“分享”获…

【CMake】CMake从入门到实战系列(十六)—— CMake中设置交叉编译

文章目录 一、前言二、切换编译器的方法1、修改系统环境变量来指定编译器2、CMake命令行中指定编译器3、CMakeLists.txt中指定编译器4、示例 一、前言 CMake是一个强大的跨平台的编译工具&#xff0c;实际嵌入式开发过程中&#xff0c;经常需要使用到交叉编译。在Ubuntu环境中…

linux中: IDEA 由于JVM 设置内存过小,导致打开项目闪退问题

1. 找到idea安装目录 由于无法打开idea&#xff0c;只能找到idea安装目录 在linux(debian/ubuntu)中idea的插件默认安装位置和配置文件在哪里? 默认路径&#xff1a; /home/当前用户名/.config/JetBrains/IntelliJIdea2020.具体版本号/options2. 找到jvm配置文件 IDEA安装…

Visual Studio编译fatal error C1001: 编译器中发生内部错误

项目本来是能正常编译的&#xff0c;但是突然出现“fatal error C1001: 编译器中发生内部错误。” 2> (编译器文件“f:\dd\vctools\compiler\utc\src\p2\main.c”&#xff0c;第 255 行) 2> 要解决此问题&#xff0c;请尝试简化或更改上面所列位置附近的程序。 2> …

AI大模型的战场 通用大模型 vs. 垂直大模型

目录 前言1 通用大模型1.1 通用大模型简介1.2 通用大模型的优势1.3 通用大模型的挑战 2 垂直大模型2.1 垂直大模型简介2.2 垂直大模型的优势2.3 垂直大模型的挑战 3 通用大模型 vs. 垂直大模型3.1 技术层面的比较3.2 商业层面的比较3.3 未来的发展趋势 结语 前言 随着人工智能…