Deedle C# (jak to działa dla programistów)
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;
Imports Deedle
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);
}
}
Imports System
Imports Deedle
Friend Class Program
Shared Sub Main()
' Creating a series with integer keys and double values
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 from a 2D array
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
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);
}
}
Imports System
Imports Deedle
Friend Class Program
Shared Sub Main()
' Creating a series with nullable doubles to represent missing values
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 (e.g., 0.0)
Dim filledSeries = series.FillMissing(0.0)
Console.WriteLine("Series after Filling Missing Values:")
Console.WriteLine(filledSeries)
End Sub
End Class
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.
Manipulacja danymi
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);
}
}
Imports System
Imports Deedle
Friend Class Program
Shared Sub Main()
' 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("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)
' 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)
End Sub
End Class
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.
Funkcje statystyczne
Deedle udostępnia standardowe funkcje statystyczne do analizy danych. Korzystając z funkcji statystycznych, można obliczyć średnią, odchylenie standardowe i inne miary statystyczne.
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}");
}
}
Imports System
Imports Deedle
Friend Class Program
Shared Sub Main()
' Creating a series with integer keys and double values
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 the mean of the series
Dim mean = series.Mean()
Console.WriteLine($"Mean: {mean}")
' Calculate the standard deviation of the series
Dim stddev = series.StdDev()
Console.WriteLine($"Standard Deviation: {stddev}")
End Sub
End Class
This Deedle code example implements standard statistical functions Mean() and StdDev() to calculate the mean and standard deviation of a series respectively.
Tworzenie ram danych z plików CSV
Deedle pozwala w łatwy sposób tworzyć ramki danych z plików CSV. Jest to pomocne przy ładowaniu i analizowaniu danych strukturalnych.
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);
}
}
Imports System
Imports Deedle
Friend Class Program
Shared Sub Main()
' Load a data frame from a CSV file
Dim dataFrame = Frame.ReadCsv("data.csv")
Console.WriteLine("Data Frame from CSV:")
Console.WriteLine(dataFrame)
' Aggregate rows by a specified column and compute sum
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
W tym przykładzie plik CSV jest wczytywany do ramki danych, a następnie wykonywana jest operacja podsumowująca na danych.
Integracja Deedle z IronPDF
Introduction of IronPDF

IronPDF to potężna biblioteka, która pozwala tworzyć, modyfikować i wyodrębniać zawartość z plików PDF w aplikacjach .NET. Jest bardzo wszechstronny i może obsługiwać różne zadania związane z plikami PDF, takie jak generowanie plików PDF z HTML, wyodrębnianie tekstu, scalanie plików PDF i wiele więcej. Integracja IronPDF z Deedle może być szczególnie przydatna w scenariuszach analizy danych i raportowania, w których konieczne jest generowanie dynamicznych raportów na podstawie ram danych.
Instalacja IronPDF
Aby zainstalować IronPDF w projekcie .NET za pomocą konsoli NuGet Package Manager Console, dodaj następujące polecenie:
Install-Package IronPdf
Można również zainstalować IronPDF za pomocą menedżera pakietów NuGet dla rozwiązań. W wynikach wyszukiwania na NuGet znajdź pakiet IronPDF, wybierz go, a następnie kliknij przycisk "Zainstaluj". Visual Studio will handle the download and installation automatically.
Po zakończeniu instalacji można wykorzystać IronPDF w swoim projekcie.
Przykład zastosowania połączenia IronPDF z Deedle
Wyobraź sobie, że masz ramkę danych zawierającą pewne dane statystyczne, które chcesz przedstawić w raporcie PDF. Deedle może zająć się częścią dotyczącą manipulacji danymi i analizy, natomiast IronPDF może posłużyć do formatowania i generowania końcowego raportu. Na przykład można wygenerować plik PDF zawierający tabele, wykresy i statystyki opisowe, co ułatwia udostępnianie i prezentowanie danych.
Przykładowy kod przedstawiający przypadek użycia
Oto kompletny przykład kodu pokazujący, jak zintegrować Deedle z IronPDF. Stworzymy prosty raport na podstawie ramki danych Deedle i wygenerujemy plik PDF przy użyciu 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!");
}
}
}
Imports System
Imports System.Linq
Imports Deedle
Imports IronPdf
Namespace DeedleIronPDFIntegration
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Set IronPDF license key
IronPdf.License.LicenseKey = "License-Key"
' Create a sample data frame from in-memory records
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 an HTML table format
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 content
Dim renderer = New ChromePdfRenderer()
Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Save the generated PDF to a file
pdfDocument.SaveAs("f:\DeedleReport.pdf")
Console.WriteLine("PDF report created successfully!")
End Sub
End Class
End Namespace
Wynik

And that's it! Właśnie stworzyłeś w pełni funkcjonalną aplikację, która pobiera złożone dane z Deedle i przekształca je w sformatowany raport PDF przy użyciu biblioteki .NET PDF firmy IronPDF. To skuteczny sposób na przekazanie wyników analizy danych w profesjonalnym formacie.
Wnioski
W tym artykule omówiliśmy, jak zintegrować Deedle z IronPDF w celu tworzenia dynamicznych raportów PDF na podstawie ram danych. Korzystając z Deedle, można efektywnie przetwarzać i analizować dane, podczas gdy IronPDF zajmuje się tworzeniem i formatowaniem końcowego dokumentu PDF. To połączenie pozwala z łatwością generować profesjonalne raporty, automatyzując proces od analizy danych po prezentację.
IronPDF oferuje szczegółową dokumentację dotyczącą funkcji i użytkowania wraz z różnymi przykładami kodu IronPDF, które pomogą Ci rozpocząć pracę i efektywnie korzystać z jego rozbudowanych funkcji.
Explore IronPDF licensing options starting from $799. Wypróbuj to i przekonaj się, jak może to poprawić Twoje możliwości raportowania.
Często Zadawane Pytania
Do czego służy Deedle C#?
Deedle C# służy do manipulacji i analizy danych, oferując narzędzia do efektywnego zarządzania zorganizowanymi ramkami i seriami danych. Jest szczególnie przydatny w aplikacjach data science ze względu na zdolność do zarządzania brakującymi danymi, wyrównywania danych i stosowania funkcji.
Jak mogę zintegrować Deedle z generowaniem PDF w .NET?
Można zintegrować Deedle z IronPDF, aby generować dynamiczne raporty PDF z ramek danych. Deedle obsługuje manipulację danymi, podczas gdy IronPDF formatuje i generuje końcowy raport PDF zawierający tabele, wykresy i statystyki.
Jak zainstalować Deedle w projekcie .NET?
Aby zainstalować Deedle w projekcie .NET, można użyć Visual Studio do stworzenia nowej aplikacji konsolowej C#, a następnie zainstalować pakiet NuGet Deedle za pomocą komendy Install-Package Deedle i dołączyć go do projektu za pomocą using Deedle;.
Jaki jest proces tworzenia ramek danych z plików CSV za pomocą Deedle?
Aby tworzyć ramki danych z plików CSV używając Deedle, można użyć metody Frame.ReadCsv(). Umożliwia to wczytywanie zorganizowanych danych z plików CSV do ramek danych do analizy i manipulacji.
Czy Deedle może obsługiwać brakujące wartości w ramkach danych?
Tak, Deedle zapewnia solidne wsparcie w zakresie obsługi brakujących wartości w ramkach danych. Można używać funkcji takich jak FillMissing(), aby właściwie zarządzać i uzupełniać brakujące dane w serii lub ramce danych.
Jak mogę przeprowadzić analizę statystyczną za pomocą Deedle?
Deedle oferuje wbudowane funkcje statystyczne, które pozwalają na przeprowadzanie analizy danych, w tym obliczenia średniej, odchylenia standardowego i innych metryk statystycznych bezpośrednio na ramkach danych i seriach.
Jak generować raporty PDF z ramek danych w .NET?
Aby generować raporty PDF z ramek danych w .NET, można użyć Deedle do manipulacji danymi oraz IronPDF do generowania PDF. Po przetworzeniu danych za pomocą Deedle, należy użyć IronPDF do formatowania i wyprowadzania danych w profesjonalnie stylizowanym raporcie PDF.




