푸터 콘텐츠로 바로가기
.NET 도움말

Deedle C# (How It Works For Developers)

Deedle C#

Deedle is a powerful library for data manipulation and data analysis. It offers entire data frames and series, allowing you to handle structured data frames efficiently. Deedle provides tools for missing data, aligning data, and applying helper functions with static members ofNullables and ofObservations. It is widely used in data science for its flexibility and performance.

IronPDF is a library for creating and manipulating PDF documents in .NET. It helps you generate PDFs from HTML, convert images to PDFs, and extract content from PDF files. IronPDF simplifies PDF tasks in your .NET projects.

In this article, you'll learn how to get started with Deedle for C#, set it up in your .NET projects using Visual Studio, and implement key features with automatically generated documentation. You'll see code examples and explanations to help you understand how to use Deedle effectively, including how to apply a specified function.

Getting Started with Deedle C#

Setting Up Deedle in .NET Projects

To begin, create a new C# Console Application project in Visual Studio.

To use Deedle in your .NET project, you need to install the Deedle NuGet package. Run the following command in the NuGet console:

Install-Package Deedle

Once installed, you need to import the Deedle namespace into your project:

using Deedle;
using Deedle;
$vbLabelText   $csharpLabel

A Basic Code Example

Let's start with a basic example to create and manipulate a data frame. This will help you understand the basics of Deedle.

using System;
using Deedle;

class Program
{
    static void Main()
    {
        // Creating a series with integer keys and double values
        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 from a 2D array
        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 with integer keys and double values
        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 from a 2D array
        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);
    }
}
$vbLabelText   $csharpLabel

In this example, you create a series with integer row keys and double values. Then, you create a data frame using a 2D array of double values. You index the rows with integers and the columns with strings.

Implementing Features of Deedle C#

Handling Missing Values

Handling missing values is crucial in data manipulation. Deedle provides robust support for missing data. You can create a series with missing values and perform operations to handle them.

using System;
using Deedle;

class Program
{
    static void Main()
    {
        // Creating a series with nullable doubles to represent missing values
        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 (e.g., 0.0)
        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()
    {
        // Creating a series with nullable doubles to represent missing values
        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 (e.g., 0.0)
        var filledSeries = series.FillMissing(0.0);
        Console.WriteLine("Series after Filling Missing Values:");
        Console.WriteLine(filledSeries);
    }
}
$vbLabelText   $csharpLabel

This example creates a series with missing values and fills them with a specified value. You can also use static member methods like ofOptionalObservations and ofValues for more complex scenarios.

Data Manipulation

Deedle allows you to perform various data manipulation tasks. You can filter, transform, and aggregate data in data frames.

using System;
using Deedle;

class Program
{
    static void Main()
    {
        // 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("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);

        // Add a new column 'C' which is the sum of columns 'A' and 'B'
        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()
    {
        // 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("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);

        // Add a new column 'C' which is the sum of columns 'A' and 'B'
        dataFrame.AddColumn("C", dataFrame["A"] + dataFrame["B"]);
        Console.WriteLine("Transformed Data Frame with New Column 'C':");
        Console.WriteLine(dataFrame);
    }
}
$vbLabelText   $csharpLabel

This example demonstrates filtering rows based on a condition and adding a new column with transformed data. Deedle implements standard frame extension methods to make data analysis straightforward.

Statistical Functions

Deedle provides standard statistical functions to analyze data. Using the statistical functions, you can calculate the mean, standard deviation, and other statistical measures.

using System;
using Deedle;

class Program
{
    static void Main()
    {
        // Creating a series with integer keys and double values
        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 the mean of the series
        var mean = series.Mean();
        Console.WriteLine($"Mean: {mean}");

        // Calculate the standard deviation of the series
        var stddev = series.StdDev();
        Console.WriteLine($"Standard Deviation: {stddev}");
    }
}
using System;
using Deedle;

class Program
{
    static void Main()
    {
        // Creating a series with integer keys and double values
        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 the mean of the series
        var mean = series.Mean();
        Console.WriteLine($"Mean: {mean}");

        // Calculate the standard deviation of the series
        var stddev = series.StdDev();
        Console.WriteLine($"Standard Deviation: {stddev}");
    }
}
$vbLabelText   $csharpLabel

This Deedle code example implements standard statistical functions Mean() and StdDev() to calculate the mean and standard deviation of a series respectively.

Creating Data Frames from CSV

Deedle allows you to create data frames from CSV files easily. This is helpful for loading and analyzing structured data.

using System;
using Deedle;

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

        // Aggregate rows by a specified column and compute sum
        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 a data frame from a CSV file
        var dataFrame = Frame.ReadCsv("data.csv");
        Console.WriteLine("Data Frame from CSV:");
        Console.WriteLine(dataFrame);

        // Aggregate rows by a specified column and compute sum
        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);
    }
}
$vbLabelText   $csharpLabel

This example reads a CSV file into a data frame and performs a summary operation on the data.

Integrating Deedle with IronPDF

Introduction of IronPDF

Deedle C# (How It Works For Developers): Figure 1 - IronPDF for .NET: The C# PDF Library

IronPDF is a powerful library that allows you to create, manipulate, and extract content from PDF files in .NET applications. It's highly versatile and can handle various PDF-related tasks such as generating PDFs from HTML, extracting text, merging PDFs, and much more. Integrating IronPDF with Deedle can be particularly useful for data analysis and reporting scenarios where you need to generate dynamic reports from data frames.

Installation of IronPDF

To install IronPDF in your .NET project using NuGet Package Manager Console, add the following command:

Install-Package IronPdf

Or you can also install IronPDF by using NuGet Package Manager for Solutions. Look for the IronPDF package on NuGet in the search results, select it, and then click on the "Install" button. Visual Studio will handle the download and installation automatically.

After installation is complete, IronPDF can be utilized for your project.

Use Case of Merging IronPDF with Deedle

Imagine you have a data frame with some statistical data that you want to present in a PDF report. Deedle can handle the data manipulation and analysis part, while IronPDF can be used to format and generate the final report. For instance, you can generate a PDF that includes tables, charts, and descriptive statistics, making the data easy to share and present.

Code Example of Use Case

Here's a complete code example demonstrating how to integrate Deedle with IronPDF. We'll create a simple report from a Deedle data frame and generate a PDF using IronPDF.

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

namespace DeedleIronPDFIntegration
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set IronPDF license key
            IronPdf.License.LicenseKey = "License-Key";

            // Create a sample data frame from in-memory records
            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 an HTML table format
            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 content
            var renderer = new ChromePdfRenderer();
            var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);

            // Save the generated PDF to a 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)
        {
            // Set IronPDF license key
            IronPdf.License.LicenseKey = "License-Key";

            // Create a sample data frame from in-memory records
            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 an HTML table format
            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 content
            var renderer = new ChromePdfRenderer();
            var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);

            // Save the generated PDF to a file
            pdfDocument.SaveAs("f:\\DeedleReport.pdf");
            Console.WriteLine("PDF report created successfully!");
        }
    }
}
$vbLabelText   $csharpLabel

Output

Deedle C# (How It Works For Developers): Figure 2 - Output PDF generated using IronPDF and Deedle

And that's it! You've just created a fully functional application that takes complex data from Deedle and turns it into a formatted PDF report using IronPDF's .NET PDF Library. It's a powerful way to communicate your data analysis results in a professional format.

Conclusion

In this article, we've explored how to integrate Deedle with IronPDF to create dynamic PDF reports from data frames. Using Deedle, you can efficiently manipulate and analyze data, while IronPDF handles the creation and formatting of the final PDF document. This combination allows you to generate professional reports with ease, automating the process from data analysis to presentation.

IronPDF offers detailed documentation on features and usage along with various IronPDF code examples to guide you on how to get started and effectively use its extensive features.

Explore IronPDF licensing options starting from $799. Give it a try and see how it can enhance your reporting capabilities.

자주 묻는 질문

Deedle C#은 어떤 용도로 사용되나요?

Deedle C#은 데이터 조작 및 분석에 사용되며, 구조화된 데이터 프레임과 시리즈를 효율적으로 처리할 수 있는 도구를 제공합니다. 특히 누락된 데이터를 관리하고, 데이터를 정렬하고, 함수를 적용하는 기능으로 데이터 과학 애플리케이션에 유용합니다.

Deedle과 .NET의 PDF 생성을 통합하려면 어떻게 해야 하나요?

데이터 프레임에서 동적 PDF 보고서를 생성하기 위해 Deedle을 IronPDF와 통합할 수 있습니다. Deedle은 데이터 조작을 처리하고 IronPDF는 표, 차트 및 통계가 포함된 최종 PDF 보고서의 서식을 지정하고 생성하는 데 사용됩니다.

.NET 프로젝트에 Deedle을 어떻게 설치하나요?

.NET 프로젝트에 Deedle을 설치하려면 Visual Studio를 사용하여 새 C# 콘솔 애플리케이션을 만든 다음 Install-Package Deedle 명령을 사용하여 Deedle NuGet 패키지를 설치하고 using Deedle;로 프로젝트에 포함할 수 있습니다.

Deedle을 사용하여 CSV 파일에서 데이터 프레임을 만드는 과정은 무엇인가요?

Deedle을 사용하여 CSV 파일에서 데이터 프레임을 만들려면 Frame.ReadCsv() 메서드를 사용할 수 있습니다. 이를 통해 CSV 파일의 구조화된 데이터를 데이터 프레임으로 로드하여 분석 및 조작할 수 있습니다.

Deedle은 데이터 프레임의 누락된 값을 처리할 수 있나요?

예, Deedle은 데이터 프레임의 누락된 값 처리를 강력하게 지원합니다. FillMissing()과 같은 함수를 사용하여 시리즈 또는 데이터 프레임 내에서 누락된 데이터를 적절하게 관리하고 채울 수 있습니다.

Deedle을 사용하여 통계 분석을 수행하려면 어떻게 해야 하나요?

Deedle은 데이터 프레임과 시리즈에서 직접 평균, 표준 편차 및 기타 통계 메트릭을 계산하는 등 데이터 분석을 수행할 수 있는 내장 통계 기능을 제공합니다.

.NET의 데이터 프레임에서 PDF 보고서는 어떻게 생성하나요?

.NET의 데이터 프레임에서 PDF 보고서를 생성하려면 데이터 조작에는 Deedle을, PDF 생성에는 IronPDF를 사용할 수 있습니다. Deedle로 데이터를 조작한 후 IronPDF를 사용하여 데이터를 전문적인 스타일의 PDF 보고서로 포맷하고 출력합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.