-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Data; | ||
using ChoETL; | ||
|
||
namespace APSToolkit.Utils; | ||
|
||
public static class DataFrame | ||
{ | ||
|
||
/// <summary> | ||
/// Loads a DataFrame from a DataTable. | ||
/// </summary> | ||
/// <param name="dataTable">The DataTable to be converted into a DataFrame.</param> | ||
/// <returns>A DataFrame that represents the provided DataTable.</returns> | ||
public static Microsoft.Data.Analysis.DataFrame LoadFromDataTable(DataTable dataTable) | ||
{ | ||
Microsoft.Data.Analysis.DataFrame dataFrame = dataTable.ToDataFrame(); | ||
return dataFrame; | ||
} | ||
|
||
/// <summary> | ||
/// Loads a DataFrame from a Parquet file. | ||
/// </summary> | ||
/// <param name="filePath">The path to the Parquet file.</param> | ||
/// <returns>A DataFrame that represents the data in the Parquet file.</returns> | ||
public static Microsoft.Data.Analysis.DataFrame LoadFromParquet(string filePath) | ||
{ | ||
using (var r = new ChoParquetReader(filePath)) | ||
{ | ||
var dataFrame = r.AsDataTable(); | ||
return dataFrame.ToDataFrame(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Loads a DataFrame from a Parquet file represented as a byte array. | ||
/// </summary> | ||
/// <param name="stream">The byte array representing the Parquet file.</param> | ||
/// <returns>A DataFrame that represents the data in the Parquet file.</returns> | ||
public static Microsoft.Data.Analysis.DataFrame LoadFromParquet(byte[] stream) | ||
{ | ||
Stream s = new MemoryStream(stream); | ||
using (var r = new ChoParquetReader(s)) | ||
{ | ||
var dataFrame = r.AsDataTable(); | ||
return dataFrame.ToDataFrame(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Loads a DataFrame from an Excel file. | ||
/// </summary> | ||
/// <param name="filePath">The path to the Excel file.</param> | ||
/// <param name="sheetName">The name of the sheet in the Excel file to load.</param> | ||
/// <returns>A DataFrame that represents the data in the specified sheet of the Excel file.</returns> | ||
public static Microsoft.Data.Analysis.DataFrame LoadFromExcel(string filePath, string sheetName) | ||
{ | ||
DataTable dt = ExcelUtils.ReadDataFromExcelToDataTable(filePath, sheetName); | ||
return dt.ToDataFrame(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.