.NET ヘルプ

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

Deedle C

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

IronPDFは、.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
$vbLabelText   $csharpLabel

基本的なコード例

データフレームを作成および操作する基本的な例から始めましょう。 これは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
$vbLabelText   $csharpLabel

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

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
$vbLabelText   $csharpLabel

この例では、欠損値を含むシリーズを作成し、指定された値で埋めます。 より複雑なシナリオに対して、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
$vbLabelText   $csharpLabel

この例では、条件に基づいて行をフィルタリングし、変換されたデータを持つ新しい列を追加する方法を示します。 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
$vbLabelText   $csharpLabel

この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
$vbLabelText   $csharpLabel

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

IronPDFとDeedleの統合

IronPDFの紹介

Deedle C#(開発者向けの仕組み): 図 1 - IronPDF for .NET: C# PDFライブラリ

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

IronPDFのインストール

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

Install-Package IronPdf

または、ソリューションのためにNuGetパッケージマネージャーを使用してIronPDFをインストールすることもできます。 検索結果でNuGetの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
$vbLabelText   $csharpLabel

出力

Deedle C# (開発者向けの動作原理): 図2 - IronPDFとDeedleを使用して生成された出力PDF

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

結論

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

IronPDFは、始め方やその豊富な機能を効果的に使用するためのガイドとして、機能や使用法に関する詳細なドキュメントと、様々なIronPDFのコード例を提供しています。

IronPDF ライセンス オプションを探索する、$749 から始める。 試してみて、レポート作成能力がどのように向上するかをご確認ください。

チペゴ
ソフトウェアエンジニア
チペゴは優れた傾聴能力を持ち、それが顧客の問題を理解し、賢明な解決策を提供する助けとなっています。彼は情報技術の学士号を取得後、2023年にIron Softwareチームに加わりました。現在、彼はIronPDFとIronOCRの2つの製品に注力していますが、顧客をサポートする新しい方法を見つけるにつれて、他の製品に関する知識も日々成長しています。Iron Softwareでの協力的な生活を楽しんでおり、さまざまな経験を持つチームメンバーが集まり、効果的で革新的な解決策を提供することに貢献しています。チペゴがデスクを離れているときは、良い本を楽しんだり、サッカーをしていることが多いです。
< 以前
Dottrace .NET Core(開発者向けの仕組み)
次へ >
C# デコンストラクタ (開発者向けの仕組み)