.NET幫助 Deedle C#(對於開發者的運行原理) Jacob Mellor 更新:2025年6月22日 下載 IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 Deedle C Deedle 是一個強大的程式庫,用於數據操作和數據分析。 它提供完整的數據框和序列,允許您有效地處理結構化數據框。 Deedle 提供工具來處理缺失數據、對齊數據,以及透過靜態成員 ofNullables 和 ofObservations 應用輔助函數。 因其靈活性和效能,它廣泛應用於數據科學。 IronPDF 是一個在 .NET 中創建和操作 PDF 文件的程式庫。 它幫助您從 HTML 生成 PDF,將圖像轉換為 PDF,並從 PDF 文件中提取內容。 IronPDF 簡化了您在 .NET 專案中的 PDF 任務。 在本文中,您將學習如何開始使用 Deedle for C#,如何在您的 .NET 專案中使用 Visual Studio 設置它,並透過自動生成的文件實現關鍵功能。 您將看到代碼範例和解釋,幫助您理解如何有效使用 Deedle,包括如何應用指定的函數。 Getting Started with 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 在此例中,您創建了一個帶有整數行鍵和雙精度值的序列。 然後,您使用雙精度值的 2D 陣列創建一個數據框。 您用整數索引行,用字串索引列。 Implementing Features of 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 Package Manager Console 在您的 .NET 專案中安裝 IronPDF,請添加以下命令: Install-Package IronPdf 或者,您也可以使用解決方案的 NuGet Package Manager 安裝 IronPDF。 在搜索結果中查找 NuGet 上的 IronPDF 套件,選擇它,然後點擊"安裝"按鈕。 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 輸出 就是這樣! 您已經創建了一個完全功能的應用程式,將 Deedle 的複雜數據轉換為使用 IronPDF 的 .NET PDF 程式庫 的格式化 PDF 報告。 這是一種強大的方式,可以以專業格式傳達您的數據分析結果。 結論 在本文中,我們已經探索了如何將 Deedle 與 IronPDF 整合,以從數據框創建動態 PDF 報告。 使用 Deedle,您可以有效地操作和分析數據,而 IronPDF 處理最終 PDF 文件的創建和格式化。 此結合使您能夠輕鬆生成專業報告,從數據分析到呈現的過程自動化。 IronPDF 提供詳細的功能和使用文件以及各種IronPDF 代碼範例,指導您如何入門及有效使用其廣泛的功能。 探索 IronPDF 授權選項,從 $799 開始。 試試看,看看它如何增強您的報告能力。 常見問題解答 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報告中。 Jacob Mellor 立即與工程團隊聊天 首席技術官 Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。 相關文章 更新2026年2月20日 銜接 CLI 簡化與 .NET : 使用 Curl DotNet 與 IronPDF for .NET Jacob Mellor 藉由 CurlDotNet 彌補了這方面的不足,CurlDotNet 是為了讓 .NET 生態系統能熟悉 cURL 而建立的函式庫。 閱讀更多 更新2025年12月20日 RandomNumberGenerator C# 使用RandomNumberGenerator C#類可以幫助將您的PDF生成和編輯項目提升至新水準 閱讀更多 更新2025年12月20日 C#字符串等於(它如何對開發者起作用) 當結合使用強大的PDF庫IronPDF時,開關模式匹配可以讓您構建更智能、更清晰的邏輯來進行文檔處理 閱讀更多 Dottrace .NET Core (對開發者如何運作)C# Deconstructor(對於開發者...
更新2026年2月20日 銜接 CLI 簡化與 .NET : 使用 Curl DotNet 與 IronPDF for .NET Jacob Mellor 藉由 CurlDotNet 彌補了這方面的不足,CurlDotNet 是為了讓 .NET 生態系統能熟悉 cURL 而建立的函式庫。 閱讀更多