-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNewDataframe.ps1
54 lines (48 loc) · 2.08 KB
/
NewDataframe.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function New-DataFrame {
<#
.Synopsis
Creates an array of objects, size-mutable, can be heterogeneous, tabular data
.Example
New-DataFrame (Get-DateRange 1/1 -periods 5) p1,p2,3 {Get-Random}
Index p1 p2 3
----- -- -- -
2020-01-01 708420917 1112428663 523426202
2020-01-02 1643869654 2086787197 1127195815
2020-01-03 1095068483 2006354687 1612194161
2020-01-04 1561123134 1004618008 1431794170
2020-01-05 851611997 189055864 871342612
.Example
New-DataFrame (Get-DateRange 1/1 -periods 5) p1,p2,3
Index p1 p2 3
----- -- -- -
2020-01-01 [missing] [missing] [missing]
2020-01-02 [missing] [missing] [missing]
2020-01-03 [missing] [missing] [missing]
2020-01-04 [missing] [missing] [missing]
2020-01-05 [missing] [missing] [missing]
.Example
New-DataFrame (Get-DateRange 1/1 -periods 5 -freq M) person,state,region {Invoke-Generate "$args"}
Index person state region
----- ------ ----- ------
2020-01-01 Jalen Austin Oklahoma East
2020-02-01 Jaydon Pratt Nevada North
2020-03-01 Jazlynn Zuniga Florida West
2020-04-01 Dylan Nash Nebraska South
2020-05-01 Jabari Dodson Massachusetts West
.Example
New-DataFrame -data (1..3) -propertyNames a,b,c,d -getRandomData {2*[math]::pi}
Index a b c d
----- - - - -
1 6.28318530717959 6.28318530717959 6.28318530717959 6.28318530717959
2 6.28318530717959 6.28318530717959 6.28318530717959 6.28318530717959
3 6.28318530717959 6.28318530717959 6.28318530717959 6.28318530717959
#>
param($data, $propertyNames, [scriptblock]$getRandomData = { '[missing]' })
foreach ($row in $data) {
$obj = [Ordered]@{Index = $row }
foreach ($propertyName in $propertyNames) {
$obj.$propertyName = &$getRandomData $propertyName
}
[PSCustomObject]$obj
}
}