{"id":14063976,"url":"https://github.com/dfinke/PSDataFrame","last_synced_at":"2025-07-29T17:31:15.376Z","repository":{"id":66743345,"uuid":"231110588","full_name":"dfinke/PSDataFrame","owner":"dfinke","description":"Use PowerShell to make data exploration easy","archived":false,"fork":false,"pushed_at":"2020-01-01T15:18:51.000Z","size":299,"stargazers_count":26,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-03T07:06:06.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfinke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-12-31T15:29:51.000Z","updated_at":"2024-03-21T11:41:51.000Z","dependencies_parsed_at":"2023-07-08T16:45:19.684Z","dependency_job_id":null,"html_url":"https://github.com/dfinke/PSDataFrame","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSDataFrame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSDataFrame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSDataFrame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinke%2FPSDataFrame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfinke","download_url":"https://codeload.github.com/dfinke/PSDataFrame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228032919,"owners_count":17858917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:03:36.294Z","updated_at":"2024-12-04T02:30:56.554Z","avatar_url":"https://github.com/dfinke.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"\u003c!-- chapter start --\u003e\n\n[An Introduction to DataFrame](https://devblogs.microsoft.com/dotnet/an-introduction-to-dataframe/)\n\n\u003e Microsoft is announcing the preview of a DataFrame type for .NET to make data exploration easy\n\nThe functions in the PowerShell `cvtToDF` is a proof of concept allowing you to easily transform Powershell arrays into a DataFrame and then explore.\n\nThere are a couple of other functions `Out-DataFrame` which formats it to more PowerShell readable output and `Add-ToDF` that lets you manipulate data in a column.\n\n## Test data\n\nHere is the sample data, save in both a `csv` and `Excel` file for testing.\n\n|Region|Item|TotalSold|DateSold|Factor|\n|---|---|---|---|---|\nWest|drill|29|12/2|2.1\nSouth|lime|19|12/21|2.1\nWest|nail|57|12/23|2.1\nWest|melon|1|12/12|2.1\nNorth|saw|88|12/22|2.1\nSouth|avocado|42|12/24|2.1\nNorth|screws|86|12/25|2.1\nWest|avocado|7|12/27|2.1\nEast|avocado|83|12/29|2.1\nWest|drill|89|12/28|2.1\n\n## PowerShell CSV and DataFrames\n\nHere, you dot source the PowerShell script and you can create a `DataFrame` from `CSV` data using the built-in `Import-Csv` PowerShell function  `ConvertTo-DataFrame (Import-Csv .\\testData.csv)`.\n\n```powershell\n. .\\cvtToDF.ps1\n\n(ConvertTo-DataFrame (Import-Csv .\\testData.csv)).GroupBy(\"Region\").Sum(\"TotalSold\").Sort(\"Region\") | Out-DataFrame\n```\n\n```\nRegion TotalSold\n------ ---------\nEast          83\nNorth        174\nSouth         61\nWest         183\n```\n\n`ConvertTo-DataFrame` returns a DataFrame so you can then do things like `GroupBy`, `Sum`, and `Sort` to get these results.\n\n## PowerShell Excel and DataFrames\n\nSince we're using PowerShell, we can pass any PowerShell array containing objects to `ConvertTo-DataFrame`.\n\nHere, we're using `Import-Excel` to read a spreadsheet to create the DataFrame.\n\n***Note***: You can get the PowerShell Excel module from the PowerShell Gallery `Install-Module ImportExcel`.\n\n```powershell\n. .\\cvtToDF.ps1\n\n(ConvertTo-DataFrame (Import-Excel .\\testData.xlsx)).GroupBy(\"Region\").Sum(\"TotalSold\").Sort(\"Region\") | Out-DataFrame\n```\n\n```\nRegion TotalSold\n------ ---------\nEast          83\nNorth        174\nSouth         61\nWest         183\n```\n\nAs before, `ConvertTo-DataFrame` returns a DataFrame so you can then use the `GroupBy`, `Sum`, and `Sort` methods to get these results.\n\n## Perform a Computation\n\nThe DataFrame and DataFrameColumn classes expose a number of useful APIs. `Add-ToDF` *PowerShellizes* the `Add` method.\n\n```powershell\n. .\\cvtToDF.ps1\n\n$df = ConvertTo-DataFrame (Import-Excel .\\testData.csv)\nAdd-ToDF -targetDF $df -ColumnName TotalSold -Value 100\n\n# C# syntax\n# $df[TotalSold].Add(100, $false)\n\n# Add-ToDF -targetDF $df -ColumnName TotalSold -Value 100 -Inplace\n\n# C# syntax\n# $df[TotalSold].Add(100, $true)\n```\n\nIt adds 100 to all the values in the `ColumnName` and returns them. If you use the `-InPlace` switch, it also updates the values in the DataFrame.\n\n```\n129\n119\n157\n101\n188\n142\n186\n107\n183\n189\n```\n\n## Summary\n\nThe Microsoft DataFrame is a preview, and `ConvertTo-DataFrame` a proof of concept. It's an excellent playground to make data exploration easy.\n\nDefinitely give it a try.\n\n\u003c!-- chapter end --\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinke%2FPSDataFrame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfinke%2FPSDataFrame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinke%2FPSDataFrame/lists"}