.NET幫助 Deedle C#(對於開發者的運行原理) Curtis Chau 更新日期:6月 22, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Deedle C Deedle 是一個用於資料操作和資料分析的強大函式庫。 它提供完整的資料框和序列,讓您能高效地處理結構化資料框。 Deedle 提供用於遺漏資料、對齊資料以及使用 ofNullables 和 ofObservations 等靜態成員的輔助函數。 它因其靈活性和性能廣泛應用於數據科學。 IronPDF 是一個用於在 .NET 中創建和操作 PDF 文件的函式庫。 它幫助您從 HTML 生成 PDF、將圖片轉換為 PDF 以及從 PDF 文件提取內容。 IronPDF 簡化了您 .NET 專案中的 PDF 任務。 在這篇文章中,您將學習如何開始使用 Deedle 於 C#,在您的 .NET 專案中使用 Visual Studio 設置它,並實現以自動生成的文件為基礎的主要功能。 您將看到代碼示例及解釋,以幫助您理解如何有效地使用 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 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 $vbLabelText $csharpLabel 在這個例子中,您創建了一個帶有整數行鍵和雙精度值的序列。 然後,您使用雙精度值的二維數組創建了一個數據框。 您使用整數作為行索引和字串作為列索引。 實施 Deedle C# 的功能 處理遺漏值 在資料操作中,處理缺失數據是至關重要的。 Deedle 提供對缺失數據的強大支援。 您可以創建帶有缺失值的序列,並執行操作以處理它們。 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 $vbLabelText $csharpLabel 此示例創建了一個帶有缺失值的序列,並用指定值填充這些缺失值。 您還可以使用像 ofOptionalObservations 和 ofValues 這樣的靜態成員方法處理更複雜的場景。 數據操作 Deedle 允許您執行各種數據操作任務。 您可以在數據框中篩選、轉換和聚合數據。 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 $vbLabelText $csharpLabel 此示例演示了基於條件篩選行以及向數據中添加轉換資料的新列。 Deedle 實現了標準框框擴展方法,使數據分析變得簡單明瞭。 統計函數 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, 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 $vbLabelText $csharpLabel 此 Deedle 代碼示例實現了標準統計函數 Mean() 和 StdDev(),分別計算一個系列的平均值和標準差。 從 CSV 創建數據框 Deedle 允許您輕鬆地從 CSV 文件創建數據框。 這有助於載入和分析結構化數據。 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 $vbLabelText $csharpLabel 此示例將 CSV 文件讀入數據框,並對數據執行摘要操作。 將 Deedle 與 IronPDF 集成 IronPDF 的介紹 IronPDF 是一個強大的函式庫,允許您在 .NET 應用中創建、操作和提取 PDF 文件內容。 它高度多功能,能夠處理各種與 PDF 相關的任務,例如從HTML 生成PDF、提取文本、合併 PDF 以及更多其他功能。 將 IronPDF 與 Deedle 集成對於需要從數據框生成動態報告的數據分析和報告場景特別有用。 安裝 IronPDF 要使用 NuGet 套件管理控制台在您的 .NET 專案中安裝 IronPDF,請添加以下命令: Install-Package IronPdf 或者您還可以使用解決方案的 NuGet 套件管理器來安裝 IronPDF。 在搜索結果中查找 IronPDF 套件在 NuGet 上,選擇它,然後單擊 "安裝" 按鈕。 Visual Studio 將自動處理下載和安裝。 安裝完成後,IronPDF 可以在您的專案中使用。 將 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) { // 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 $vbLabelText $csharpLabel 輸出 就是這樣! 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. 這是一個以專業格式傳達您數據分析結果的強大方法。 結論 In this article, we've explored how to integrate Deedle with IronPDF to create dynamic PDF reports from data frames. 使用 Deedle,您可以高效地操作和分析數據,而 IronPDF 則處理最終 PDF 文件的創建和格式化。 這種組合使您能夠輕鬆生成專業報告,從數據分析到呈現過程自動化。 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. 探索 IronPDF 授權選項,從Lite授權開始。 試一試,看看它如何增強您的報告能力。 常見問題解答 Deedle C#用於什麼? Deedle C#被用於數據處理和分析,提供工具以高效處理結構化數據框和系列。它特別在數據科學應用中實用,因其能夠管理缺失數據、對齊數據和應用函數。 如何在.NET中將Deedle與PDF生成集成? 你可以將Deedle與IronPDF整合,從數據框生成動態PDF報告。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進行數據處理和IronPDF進行PDF生成。在使用Deedle處理完數據後,用IronPDF格式化並輸出到專業風格的PDF報告中。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 相關文章 更新日期 9月 4, 2025 RandomNumberGenerator C# 使用RandomNumberGenerator C#類可以幫助將您的PDF生成和編輯項目提升至新水準 閱讀更多 更新日期 9月 4, 2025 C#字符串等於(它如何對開發者起作用) 當結合使用強大的PDF庫IronPDF時,開關模式匹配可以讓您構建更智能、更清晰的邏輯來進行文檔處理 閱讀更多 更新日期 8月 5, 2025 C#開關模式匹配(對開發者來說是如何工作的) 當結合使用強大的PDF庫IronPDF時,開關模式匹配可以讓您構建更智能、更清晰的邏輯來進行文檔處理 閱讀更多 Dottrace .NET Core(對於開發者的運行原理)C# Deconstructor(對於開發者...