.NET ヘルプ

Deedle C#(開発者向け機能説明)

更新済み 7月 1, 2024
共有:

Deedle C

Deedleは、強力かつ柔軟な統計機能を持つデータフレームライブラリです。特に金融データ、科学データ、時系列データの操作に適しています。Deedleは、F#とC#向けに設計されており、多くの便利な機能と操作性を提供します。

主な機能

  • データの読み込みと保存: CSV、Excel、またはその他の形式のデータファイルを簡単に読み込んだり、保存したりできます。
  • 時系列操作: 時系列データの処理に特化した機能を持ち、時間帯によるデータの操作が容易です。
  • グループ化と集約: データフレームの行や列をグループ化し、さまざまな方法で集約することが可能です。
  • 欠損データの処理: 欠損データを巧みに扱うための様々なツールが用意されています。

以下に、金融データを使用した簡単な例を示します。

// Deedleライブラリを使用してデータフレームを作成
var df = Frame.ReadCsv("data.csv");

// 時系列データのフィルタリング
var filtered = df.Rows.Where(row => row.GetAs<DateTime>("Date") > new DateTime(2020, 1, 1));

// 集計と分析
var statistics = filtered.AggregateColumns("Price", col => col.Mean());

// 結果を表示
Console.WriteLine(statistics);
// Deedleライブラリを使用してデータフレームを作成
var df = Frame.ReadCsv("data.csv");

// 時系列データのフィルタリング
var filtered = df.Rows.Where(row => row.GetAs<DateTime>("Date") > new DateTime(2020, 1, 1));

// 集計と分析
var statistics = filtered.AggregateColumns("Price", col => col.Mean());

// 結果を表示
Console.WriteLine(statistics);
' Deedleライブラリを使用してデータフレームを作成
Dim df = Frame.ReadCsv("data.csv")

' 時系列データのフィルタリング
Dim filtered = df.Rows.Where(Function(row) row.GetAs(Of DateTime)("Date") > New DateTime(2020, 1, 1))

' 集計と分析
Dim statistics = filtered.AggregateColumns("Price", Function(col) col.Mean())

' 結果を表示
Console.WriteLine(statistics)
VB   C#

Deedleは、Iron Softwareの製品と組み合わせることで、さらに強力なデータ解析能力を提供します。例えば、IronXLを使用してExcelファイルを直接操作したり、IronOCRを使用してスキャンした文書からデータを抽出したりすることが可能です。

Deedle は、データ操作とデータ分析のための強力なライブラリです。 それは、データフレームとシリーズ全体を提供し、構造化されたデータフレームを効率的に処理することを可能にします。 Deedleは、欠損データの処理、データの整列、およびstaticメンバーofNullablesおよびofObservationsを使用したヘルパー関数の適用に関するツールを提供します。 データサイエンスにおいて、その柔軟性とパフォーマンスのために広く使用されています。

IronPDF(アイアンPDF) は、.NETでPDFドキュメントの作成と操作を行うためのライブラリです。 HTMLからPDFを生成し、画像をPDFに変換し、PDFファイルからコンテンツを抽出するのに役立ちます。 IronPDFは、.NETプロジェクトにおけるPDFタスクを簡素化します。

この記事では、C#用のDeedleの使用を開始する方法、Visual Studioを使用して.NETプロジェクトに設定する方法、および自動生成されたドキュメントを使用して重要な機能を実装する方法について学びます。 Deedleを効果的に使用する方法を理解するために、指定された関数を適用する方法を含むコード例と説明が表示されます。

Deedle C# の始め方

.NETプロジェクトにおけるDeedleの設定

始めるには、Visual Studioで新しいC#コンソールアプリケーションプロジェクトを作成します。 ビジュアルスタジオ.

.NETプロジェクトでDeedleを使用するには、Deedle NuGetパッケージをインストールする必要があります。 NuGetコンソールで次のコマンドを実行してください:

Install-Package Deedle

インストール後、プロジェクトにDeedle名前空間をインポートする必要があります。

using Deedle;
using Deedle;
Imports Deedle
VB   C#

基本的なコード例

データフレームを作成および操作する基本的な例から始めましょう。 これはDeedleの基本を理解するのに役立ちます。

using System;
using Deedle;
class Program
{
    static void Main()
    {
        // Creating a series
        var series = new Series<int, double>(new[] { 1, 2, 3 }, new[] { 3.5, 4.2, 5.1 });
        Console.WriteLine("Series:");
        Console.WriteLine(series);

        // Creating a data frame
        var rowIndex = new[] { 1, 2, 3 };
        var colIndex = new[] { "A", "B" };
        var data = new double[,] { { 1.0, 3.5 }, { 2.0, 4.2 }, { 3.0, 5.1 } };
        var dataFrame = Frame.FromArray2D(data)
                             .IndexRowsWith(rowIndex)
                             .IndexColumnsWith(colIndex);
        Console.WriteLine("Data Frame:");
        Console.WriteLine(dataFrame);
    }
}
using System;
using Deedle;
class Program
{
    static void Main()
    {
        // Creating a series
        var series = new Series<int, double>(new[] { 1, 2, 3 }, new[] { 3.5, 4.2, 5.1 });
        Console.WriteLine("Series:");
        Console.WriteLine(series);

        // Creating a data frame
        var rowIndex = new[] { 1, 2, 3 };
        var colIndex = new[] { "A", "B" };
        var data = new double[,] { { 1.0, 3.5 }, { 2.0, 4.2 }, { 3.0, 5.1 } };
        var dataFrame = Frame.FromArray2D(data)
                             .IndexRowsWith(rowIndex)
                             .IndexColumnsWith(colIndex);
        Console.WriteLine("Data Frame:");
        Console.WriteLine(dataFrame);
    }
}
Imports System
Imports Deedle
Friend Class Program
	Shared Sub Main()
		' Creating a series
		Dim series As New Series(Of Integer, Double)( { 1, 2, 3 }, { 3.5, 4.2, 5.1 })
		Console.WriteLine("Series:")
		Console.WriteLine(series)

		' Creating a data frame
		Dim rowIndex = { 1, 2, 3 }
		Dim colIndex = { "A", "B" }
		Dim data = New Double(, ) {
			{ 1.0, 3.5 },
			{ 2.0, 4.2 },
			{ 3.0, 5.1 }
		}
		Dim dataFrame = Frame.FromArray2D(data).IndexRowsWith(rowIndex).IndexColumnsWith(colIndex)
		Console.WriteLine("Data Frame:")
		Console.WriteLine(dataFrame)
	End Sub
End Class
VB   C#

この例では、整数の行キーとダブル値を持つシリーズを作成します。 次に、二次元配列のダブル値を使用してデータフレームを作成します。 行を整数でインデックスし、列を文字列でインデックスします。

Deedle C# の機能実装

欠損値の処理

データ操作において欠損値の処理は重要です。 Deedleは欠損データに対する強力なサポートを提供します。 欠損値を含むシリーズを作成し、それらを処理する操作を実行することができます。

using System;
using Deedle;
class Program
{
    static void Main()
    {
        var series = new Series<int, double?>(
            new[] { 75, 8, 47, 5 },
            new double?[] { 75.0, null, 47.0, 5.0 }
        );
        Console.WriteLine("Original Series with Missing Values:");
        Console.WriteLine(series);

        // Fill missing values with a specified value
        var filledSeries = series.FillMissing(0.0);
        Console.WriteLine("Series after Filling Missing Values:");
        Console.WriteLine(filledSeries);
    }
}
using System;
using Deedle;
class Program
{
    static void Main()
    {
        var series = new Series<int, double?>(
            new[] { 75, 8, 47, 5 },
            new double?[] { 75.0, null, 47.0, 5.0 }
        );
        Console.WriteLine("Original Series with Missing Values:");
        Console.WriteLine(series);

        // Fill missing values with a specified value
        var filledSeries = series.FillMissing(0.0);
        Console.WriteLine("Series after Filling Missing Values:");
        Console.WriteLine(filledSeries);
    }
}
Imports System
Imports Deedle
Friend Class Program
	Shared Sub Main()
		Dim series As New Series(Of Integer, Double?)( { 75, 8, 47, 5 }, New Double?() { 75.0, Nothing, 47.0, 5.0 })
		Console.WriteLine("Original Series with Missing Values:")
		Console.WriteLine(series)

		' Fill missing values with a specified value
		Dim filledSeries = series.FillMissing(0.0)
		Console.WriteLine("Series after Filling Missing Values:")
		Console.WriteLine(filledSeries)
	End Sub
End Class
VB   C#

この例では、欠損値を含むシリーズを作成し、指定された値で埋めます。 また、ofOptionalObservationsofValuesのような静的メンバーメソッドを使用して、さらに複雑なシナリオに対応することもできます。

データ操作

Deedleは、さまざまなデータ操作タスクを実行することができます。 データフレーム内のデータをフィルタリング、変換、および集約できます。

using System;
using Deedle;
class Program
{
    static void Main()
    {
        var rowIndex = new[] { 1, 2, 3 };
        var colIndex = new[] { "A", "B" };
        var data = new double[,] { { 1.0, 3.5 }, { 2.0, 4.2 }, { 3.0, 5.1 } };
        var dataFrame = Frame.FromArray2D(data)
                             .IndexRowsWith(rowIndex)
                             .IndexColumnsWith(colIndex);
        Console.WriteLine("Original Data Frame:");
        Console.WriteLine(dataFrame);

        // Filter rows where column 'A' is greater than 1.5
        var filteredFrame = dataFrame.Where(row => row.Value.GetAs<double>("A") > 1.5);
        Console.WriteLine("Filtered Data Frame:");
        Console.WriteLine(filteredFrame);

        dataFrame.AddColumn("C", dataFrame["A"] + dataFrame["B"]);
        Console.WriteLine("Transformed Data Frame with New Column 'C':");
        Console.WriteLine(dataFrame);
    }
}
using System;
using Deedle;
class Program
{
    static void Main()
    {
        var rowIndex = new[] { 1, 2, 3 };
        var colIndex = new[] { "A", "B" };
        var data = new double[,] { { 1.0, 3.5 }, { 2.0, 4.2 }, { 3.0, 5.1 } };
        var dataFrame = Frame.FromArray2D(data)
                             .IndexRowsWith(rowIndex)
                             .IndexColumnsWith(colIndex);
        Console.WriteLine("Original Data Frame:");
        Console.WriteLine(dataFrame);

        // Filter rows where column 'A' is greater than 1.5
        var filteredFrame = dataFrame.Where(row => row.Value.GetAs<double>("A") > 1.5);
        Console.WriteLine("Filtered Data Frame:");
        Console.WriteLine(filteredFrame);

        dataFrame.AddColumn("C", dataFrame["A"] + dataFrame["B"]);
        Console.WriteLine("Transformed Data Frame with New Column 'C':");
        Console.WriteLine(dataFrame);
    }
}
Imports System
Imports Deedle
Friend Class Program
	Shared Sub Main()
		Dim rowIndex = { 1, 2, 3 }
		Dim colIndex = { "A", "B" }
		Dim data = New Double(, ) {
			{ 1.0, 3.5 },
			{ 2.0, 4.2 },
			{ 3.0, 5.1 }
		}
		Dim dataFrame = Frame.FromArray2D(data).IndexRowsWith(rowIndex).IndexColumnsWith(colIndex)
		Console.WriteLine("Original Data Frame:")
		Console.WriteLine(dataFrame)

		' Filter rows where column 'A' is greater than 1.5
		Dim filteredFrame = dataFrame.Where(Function(row) row.Value.GetAs(Of Double)("A") > 1.5)
		Console.WriteLine("Filtered Data Frame:")
		Console.WriteLine(filteredFrame)

		dataFrame.AddColumn("C", dataFrame("A") + dataFrame("B"))
		Console.WriteLine("Transformed Data Frame with New Column 'C':")
		Console.WriteLine(dataFrame)
	End Sub
End Class
VB   C#

この例では、条件に基づいて行をフィルタリングし、変換されたデータを持つ新しい列を追加する方法を示します。 Deedleは、データ分析を容易にするために標準的なフレーム拡張メソッドを実装しています。

統計関数

Deedleは、データを分析するための標準的な統計関数を提供します。 統計関数を使用すると、平均、標準偏差、その他の統計測定値を計算することができます。

using System;
using Deedle;
class Program
{
    static void Main()
    {
        var series = new Series<int, double>(
            new[] { 1, 2, 3, 4 },
            new[] { 1.0, 2.0, 3.0, 4.0 }
        );
        Console.WriteLine("Series:");
        Console.WriteLine(series);

        // Calculate mean
        var mean = series.Mean();
        Console.WriteLine($"Mean: {mean}");

        // Calculate standard deviation
        var stddev = series.StdDev();
        Console.WriteLine($"Standard Deviation: {stddev}");
    }
}
using System;
using Deedle;
class Program
{
    static void Main()
    {
        var series = new Series<int, double>(
            new[] { 1, 2, 3, 4 },
            new[] { 1.0, 2.0, 3.0, 4.0 }
        );
        Console.WriteLine("Series:");
        Console.WriteLine(series);

        // Calculate mean
        var mean = series.Mean();
        Console.WriteLine($"Mean: {mean}");

        // Calculate standard deviation
        var stddev = series.StdDev();
        Console.WriteLine($"Standard Deviation: {stddev}");
    }
}
Imports System
Imports Deedle
Friend Class Program
	Shared Sub Main()
		Dim series As New Series(Of Integer, Double)( { 1, 2, 3, 4 }, { 1.0, 2.0, 3.0, 4.0 })
		Console.WriteLine("Series:")
		Console.WriteLine(series)

		' Calculate mean
		Dim mean = series.Mean()
		Console.WriteLine($"Mean: {mean}")

		' Calculate standard deviation
		Dim stddev = series.StdDev()
		Console.WriteLine($"Standard Deviation: {stddev}")
	End Sub
End Class
VB   C#

このDeedleコードの例は、Mean(平均)の標準的な統計関数を実装しています。()およびStdDev()それぞれのシリーズの平均値と標準偏差を計算します。

CSVからデータフレームを作成する

Deedleを使用すると、CSVファイルからデータフレームを簡単に作成できます。 これは構造化データの読み込みと分析に役立ちます。

using System;
using Deedle;
class Program
{
    static void Main()
    {
        // Load data frame from CSV file
        var dataFrame = Frame.ReadCsv("data.csv");
        Console.WriteLine("Data Frame from CSV:");
        Console.WriteLine(dataFrame);

        var summary = dataFrame.AggregateRowsBy<string, double>(
            new[] { "ColumnName" }, // rowKeys
            null, // columnKeys, you can pass null if not required
            v => v.Sum() // aggFunc
        );
        Console.WriteLine("Summary of Data Frame:");
        Console.WriteLine(summary);
    }
}
using System;
using Deedle;
class Program
{
    static void Main()
    {
        // Load data frame from CSV file
        var dataFrame = Frame.ReadCsv("data.csv");
        Console.WriteLine("Data Frame from CSV:");
        Console.WriteLine(dataFrame);

        var summary = dataFrame.AggregateRowsBy<string, double>(
            new[] { "ColumnName" }, // rowKeys
            null, // columnKeys, you can pass null if not required
            v => v.Sum() // aggFunc
        );
        Console.WriteLine("Summary of Data Frame:");
        Console.WriteLine(summary);
    }
}
Imports System
Imports Deedle
Friend Class Program
	Shared Sub Main()
		' Load data frame from CSV file
		Dim dataFrame = Frame.ReadCsv("data.csv")
		Console.WriteLine("Data Frame from CSV:")
		Console.WriteLine(dataFrame)

		Dim summary = dataFrame.AggregateRowsBy(Of String, Double)( { "ColumnName" }, Nothing, Function(v) v.Sum())
		Console.WriteLine("Summary of Data Frame:")
		Console.WriteLine(summary)
	End Sub
End Class
VB   C#

この例では、CSVファイルをデータフレームに読み込み、データに対して集計操作を行います。

IronPDFとDeedleの統合

IronPDFの紹介

デードルC# (開発者のための仕組み): 図1 - IronPDF for .NET: C# PDFライブラリ

IronPDFは、.NETアプリケーションでPDFファイルを作成、操作、およびコンテンツを抽出するための強力なライブラリです。 それは非常に用途が広く、PDF関連のさまざまなタスク(生成など)を処理できます。 HTMLからのPDFテキストの抽出、PDFの結合など、さらに多くの機能があります。 デードルとIronPDFを統合することは、データフレームから動的なレポートを生成する必要があるデータ分析およびレポートシナリオにおいて特に有用です。

IronPDFのインストール

以下のコマンドを追加して、NuGet パッケージ マネージャー コンソールを使用して .NET プロジェクトに IronPDF をインストールします:

Install-Package IronPdf

または、ソリューションのためにNuGetパッケージマネージャーを使用してIronPDFをインストールすることもできます。 次のものを探して IronPDFパッケージ 検索結果でそれを選択し、「インストール」ボタンをクリックします。 Visual Studio は、ダウンロードとインストールを自動的に処理します。

インストールが完了すると、IronPDF をプロジェクトで利用できます。

Use Case of Merging IronPDF with Deedle

IronPDFとDeedleの統合ユースケース

統計データを含むデータフレームがあり、それをPDFレポートとして提出したいと想像してください。 Deedleはデータの操作と分析部分を処理でき、IronPDFは最終レポートの形式設定と生成に使用できます。 例えば、データを共有および提示しやすくするために、表、チャート、記述統計を含むPDFを生成することができます。

使用例のコード例

以下は、DeedleをIronPDFと統合する方法を示す完全なコード例です。 私たちは、Deedle データフレームからシンプルなレポートを作成し、IronPDF を使用して PDF を生成します。

using System;
using System.Linq;
using Deedle;
using IronPdf;

namespace DeedleIronPDFIntegration
{
    class Program
    {
        static void Main(string[] args)
        {
            IronPdf.License.LicenseKey = "License-Key";
            // Create a sample data frame
            var data = new[]
            {
                new { Name = "Robert", Age = 30, City = "New York" },
                new { Name = "Johnny", Age = 25, City = "San Francisco" },
                new { Name = "Charlie", Age = 35, City = "Los Angeles" }
            };
            var frame = Frame.FromRecords(data);

            // Convert the data frame to HTML table
            var htmlTable = "<table border='1' cellpadding='5' cellspacing='0'><thead><tr><th>Name</th><th>Age</th><th>City</th></tr></thead><tbody>" +
                            string.Join("", frame.Rows.Select(row =>
                                $"<tr><td>{row.Value.GetAs<string>("Name")}</td><td>{row.Value.GetAs<int>("Age")}</td><td>{row.Value.GetAs<string>("City")}</td></tr>")
                            ) +
                            "</tbody></table>";

            // Wrap the HTML table in basic HTML structure with CSS styling
            var htmlContent = $@"
            <html>
            <head>
                <style>
                    table {{
                        width: 100%;
                        border-collapse: collapse;
                    }}
                    th, td {{
                        border: 1px solid black;
                        padding: 8px;
                        text-align: left;
                    }}
                    th {{
                        background-color: #f2f2f2;
                    }}
                </style>
            </head>
            <body>
                {htmlTable}
            </body>
            </html>";

            // Create a PDF from the HTML
            var renderer = new ChromePdfRenderer();
            var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);

            // Save the PDF to file
            pdfDocument.SaveAs("f:\\DeedleReport.pdf");
            Console.WriteLine("PDF report created successfully!");
        }
    }
}
using System;
using System.Linq;
using Deedle;
using IronPdf;

namespace DeedleIronPDFIntegration
{
    class Program
    {
        static void Main(string[] args)
        {
            IronPdf.License.LicenseKey = "License-Key";
            // Create a sample data frame
            var data = new[]
            {
                new { Name = "Robert", Age = 30, City = "New York" },
                new { Name = "Johnny", Age = 25, City = "San Francisco" },
                new { Name = "Charlie", Age = 35, City = "Los Angeles" }
            };
            var frame = Frame.FromRecords(data);

            // Convert the data frame to HTML table
            var htmlTable = "<table border='1' cellpadding='5' cellspacing='0'><thead><tr><th>Name</th><th>Age</th><th>City</th></tr></thead><tbody>" +
                            string.Join("", frame.Rows.Select(row =>
                                $"<tr><td>{row.Value.GetAs<string>("Name")}</td><td>{row.Value.GetAs<int>("Age")}</td><td>{row.Value.GetAs<string>("City")}</td></tr>")
                            ) +
                            "</tbody></table>";

            // Wrap the HTML table in basic HTML structure with CSS styling
            var htmlContent = $@"
            <html>
            <head>
                <style>
                    table {{
                        width: 100%;
                        border-collapse: collapse;
                    }}
                    th, td {{
                        border: 1px solid black;
                        padding: 8px;
                        text-align: left;
                    }}
                    th {{
                        background-color: #f2f2f2;
                    }}
                </style>
            </head>
            <body>
                {htmlTable}
            </body>
            </html>";

            // Create a PDF from the HTML
            var renderer = new ChromePdfRenderer();
            var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);

            // Save the PDF to file
            pdfDocument.SaveAs("f:\\DeedleReport.pdf");
            Console.WriteLine("PDF report created successfully!");
        }
    }
}
Imports System
Imports System.Linq
Imports Deedle
Imports IronPdf

Namespace DeedleIronPDFIntegration
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			IronPdf.License.LicenseKey = "License-Key"
			' Create a sample data frame
			Dim data = {
				New With {
					Key .Name = "Robert",
					Key .Age = 30,
					Key .City = "New York"
				},
				New With {
					Key .Name = "Johnny",
					Key .Age = 25,
					Key .City = "San Francisco"
				},
				New With {
					Key .Name = "Charlie",
					Key .Age = 35,
					Key .City = "Los Angeles"
				}
			}
			Dim frame = Frame.FromRecords(data)

			' Convert the data frame to HTML table
			Dim htmlTable = "<table border='1' cellpadding='5' cellspacing='0'><thead><tr><th>Name</th><th>Age</th><th>City</th></tr></thead><tbody>" & String.Join("", frame.Rows.Select(Function(row) $"<tr><td>{row.Value.GetAs(Of String)("Name")}</td><td>{row.Value.GetAs(Of Integer)("Age")}</td><td>{row.Value.GetAs(Of String)("City")}</td></tr>")) & "</tbody></table>"

			' Wrap the HTML table in basic HTML structure with CSS styling
			Dim htmlContent = $"
            <html>
            <head>
                <style>
                    table {{
                        width: 100%;
                        border-collapse: collapse;
                    }}
                    th, td {{
                        border: 1px solid black;
                        padding: 8px;
                        text-align: left;
                    }}
                    th {{
                        background-color: #f2f2f2;
                    }}
                </style>
            </head>
            <body>
                {htmlTable}
            </body>
            </html>"

			' Create a PDF from the HTML
			Dim renderer = New ChromePdfRenderer()
			Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent)

			' Save the PDF to file
			pdfDocument.SaveAs("f:\DeedleReport.pdf")
			Console.WriteLine("PDF report created successfully!")
		End Sub
	End Class
End Namespace
VB   C#

出力

ディードル C# (開発者向けの動作方法): 図2 - IronPDFとDeedleを使用して生成された出力PDF

以上です! 複雑なデータを取得する完全な機能を備えたアプリケーションを作成しました Deedle フォーマットされたPDFレポートに変換します。 IronPDF. データ分析の結果をプロフェッショナルな形式で伝える強力な方法です。

結論

以下の記事では、統合方法について探りました Deedle と一緒に IronPDF データフレームから動的なPDFレポートを作成するために。 Deedleを使用すると、データを効率的に操作・分析でき、IronPDFが最終的なPDFドキュメントの作成とフォーマットを処理します。 この組み合わせにより、データ分析からプレゼンテーションまでのプロセスを自動化し、簡単にプロフェッショナルなレポートを作成することができます。

IronPDFは詳細な ドキュメント 様々なものと 함께 コード例 使い方を始める方法と、その豊富な機能を効果的に活用する方法について案内します。

IronPDF ライセンス 価格は749ドルからです。試してみて、どのようにレポート作成機能を強化できるかをご確認ください。

< 以前
Dottrace .NET Core(開発者向けの仕組み)
次へ >
C# デコンストラクタ (開発者向けの仕組み)

準備はできましたか? バージョン: 2024.9 新発売

無料のNuGetダウンロード 総ダウンロード数: 10,659,073 View Licenses >