在生产环境中测试,无水印。
随时随地满足您的需求。
获得30天的全功能产品。
几分钟内就能启动并运行。
在您的产品试用期间,全面访问我们的支持工程团队。
Deedle 是一个用于数据操作和数据分析的强大库。 它提供了整个数据帧和序列,使您能够高效地处理结构化数据帧。 Deedle 提供工具用于处理缺失数据、对齐数据以及使用静态成员ofNullables和ofObservations应用辅助函数。 它以其灵活性和性能被广泛应用于数据科学领域。
IronPDF 是一个用于在 .NET 中创建和操作 PDF 文档的库。 它可帮助您从 HTML 生成 PDF、将图像转换为 PDF 并从 PDF 文件中提取内容。 IronPDF 简化了 .NET 项目中的 PDF 任务。
在本文中,您将了解如何开始使用 Deedle for C#,如何使用 Visual Studio 在您的 .NET 项目中设置它,以及如何使用自动生成的文档实现关键功能。 您将看到代码示例和解释,帮助您了解如何有效使用 Deedle,包括如何应用指定函数。
首先,在Visual Studio中创建一个新的C#控制台应用程序项目。
要在 .NET 项目中使用 Deedle,您需要安装 Deedle NuGet 软件包。 在 NuGet 控制台中运行以下命令:
Install-Package Deedle安装完成后,您需要将 Deedle 命名空间导入您的项目:
using Deedle;using Deedle;Imports Deedle让我们从创建和操作数据帧的基本示例开始。 这将有助于您了解 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在本示例中,您创建了一个具有整数行键和双数值的序列。 然后,您使用二维双值数组创建一个数据帧。 您需要用整数对行进行索引,用字符串对列进行索引。
处理缺失值在数据处理中至关重要。 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该示例创建了一个缺失值序列,并用指定值进行了填充。 您还可以使用静态成员方法,例如ofOptionalObservations和ofValues,用于更复杂的场景。
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本示例演示了根据条件过滤行,并添加一列新的转换数据。 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此 Deedle 代码示例实现了标准统计函数 Mean() 和 StdDev(),分别用于计算序列的均值和标准差。
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本例将 CSV 文件读入数据帧,并对数据执行汇总操作。

IronPDF for .NET 是一个功能强大的库,可让您在 .NET 应用程序中创建、操作 PDF 文件并从中提取内容。 它具有高度的多功能性,可以处理各种与PDF相关的任务,例如从HTML生成PDF、提取文本、合并PDF等。 将 IronPDF 与 Deedle 集成,对于需要从数据帧生成动态报告的数据分析和报告场景特别有用。
要使用 NuGet Package Manager Console 在 .NET 项目中安装 IronPDF,请添加以下命令:
Install-Package IronPdf或者您也可以使用 NuGet Package Manager for Solutions 安装 IronPdf。 在搜索结果中查找NuGet上的IronPDF包,选择它,然后点击“安装”按钮。 Visual Studio 将自动处理下载和安装。
安装完成后,IronPDF 即可用于您的项目。
想象一下,您有一个数据框架,其中包含一些统计数据,您希望将这些数据以 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
就这样! 您刚刚创建了一个功能齐全的应用程序,该应用程序使用Deedle中的复杂数据,并通过IronPDF的.NET PDF库将其转换为格式化的PDF报告。 这是一种以专业格式传达数据分析结果的有力方式。
在本文中,我们探讨了如何将Deedle与IronPDF集成在一起,从数据帧创建动态PDF报告。 使用 Deedle,您可以高效地操作和分析数据,而 IronPDF 则处理最终 PDF 文档的创建和格式化。 通过这种组合,您可以轻松生成专业报告,实现从数据分析到演示的流程自动化。
IronPDF 提供了详细的功能和使用文档,以及各种IronPDF 代码示例,以指导您如何入门并有效利用其广泛的功能。
探索 IronPDF 许可选项 起价为 $749 。 试试看,看看它如何提升您的报告能力。