yomise 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/to_csv.rb +41 -1
- data/lib/yomise/version.rb +1 -1
- data/lib/yomise.rb +31 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6987f2d46203deb734420f8aa9b08f076db6792890ea1a080ff58d603be9b05c
|
4
|
+
data.tar.gz: 8ebe3864cb7f76d79f5efe48a68f71af96800ed11600e44401e7871554ebdf87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f30da92c73465ec1904b4466c396bb05062fe943666af091a46db66a3b6b0b3e41d7198d4b0b14ea0b37a489d0cfeb2f295f8b3ea35829640d6d929b8ff40a52
|
7
|
+
data.tar.gz: 56d101656e8d2b202d2dbaa2a3dacdabb993efbe5661e6e7682faa0d230fb1dfe4cbbf77c4ab4ef3392f2ac7eee50a2e6305d42b61c4e423441b47e1c13d604c
|
data/lib/to_csv.rb
CHANGED
@@ -8,7 +8,7 @@ class Daru::DataFrame
|
|
8
8
|
ans = self.map(&:name).join ","
|
9
9
|
self.to_a[0].each do |item|
|
10
10
|
ans += "\n"
|
11
|
-
ans += item.map{|k, v| v}.join(",")
|
11
|
+
ans += item.map{|k, v| "\"#{v}\""}.join(",")
|
12
12
|
end
|
13
13
|
|
14
14
|
return ans
|
@@ -58,6 +58,29 @@ class Daru::DataFrame
|
|
58
58
|
self.vectors = Daru::Index.new(vector_names_ary)
|
59
59
|
self.index = Daru::Vector.new(self.index.to_a.map{_1[0]})
|
60
60
|
end
|
61
|
+
|
62
|
+
def simple_pivot(index, vectors, values, agg: :mean, index_name: nil)
|
63
|
+
|
64
|
+
# index, vectors are Arrays. 'values' is String or Array.
|
65
|
+
## 文字列データなどで最初のデータだけ欲しければ agg: :first
|
66
|
+
piv = self.pivot_table index: index, vectors: vectors, agg: :mean, values: values
|
67
|
+
piv.vectors = Daru::Index.new( piv.vectors.to_a.map { _1.join("-") } )
|
68
|
+
piv.index = Daru::Vector.new( piv.index.to_a.map { _1.join("-") } )
|
69
|
+
|
70
|
+
# indexを新しく追加
|
71
|
+
index_name ||= "Pivot_Index"
|
72
|
+
piv[index_name] = piv.index
|
73
|
+
|
74
|
+
# 順番変更
|
75
|
+
piv.order = [piv.vectors.to_a[-1]] + piv.vectors.to_a[0..-2]
|
76
|
+
|
77
|
+
return piv
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_rover
|
82
|
+
Rover::DataFrame.new(self.to_a[0])
|
83
|
+
end
|
61
84
|
|
62
85
|
alias_method :addvec, :add_vector
|
63
86
|
end
|
@@ -69,4 +92,21 @@ class Rover::DataFrame
|
|
69
92
|
enc = encoding.nil? ? "" : ":#{encoding}"
|
70
93
|
open(path, "w#{enc}") {|f| f.write self.to_csv}
|
71
94
|
end
|
95
|
+
|
96
|
+
def to_daru
|
97
|
+
Daru::DataFrame.new(self.to_a)
|
98
|
+
end
|
99
|
+
|
100
|
+
def simple_pivot(index, vectors, ...)
|
101
|
+
ddr = self.to_daru
|
102
|
+
piv = ddr.simple_pivot(index, vectors, ...)
|
103
|
+
return piv.to_rover
|
104
|
+
end
|
105
|
+
|
106
|
+
def outer_join
|
107
|
+
ddr = self.to_daru
|
108
|
+
# j = ddr.join ## 外部結合
|
109
|
+
return j.to_rover
|
110
|
+
end
|
111
|
+
|
72
112
|
end
|
data/lib/yomise/version.rb
CHANGED
data/lib/yomise.rb
CHANGED
@@ -14,23 +14,49 @@ module Yomise
|
|
14
14
|
module_function
|
15
15
|
|
16
16
|
def read(path, **opt)
|
17
|
-
return /csv$/ === path ? read_csv(path, **opt) : read_excel(path, **opt)
|
17
|
+
return /csv$/i === path ? read_csv(path, **opt) : read_excel(path, **opt)
|
18
18
|
end
|
19
19
|
|
20
20
|
# ##Generate Array from CSV File, and convert it to Hash or DataFrame.
|
21
21
|
# **opt candidate= line_from: 1, header: 0
|
22
22
|
# ver. 0.3.8~ default format=:daru
|
23
|
-
def read_csv(path, format: :daru, encoding: "utf-8", col_sep: ",", index: nil, **opt)
|
23
|
+
def read_csv(path, format: :daru, encoding: "utf-8", liberal_parsing: true, col_sep: ",", index: nil, **opt)
|
24
24
|
## TODO.. index: option that designate column number to generate DF index.
|
25
25
|
## That is, revicing set_index method.
|
26
26
|
|
27
27
|
# Get 2D Array
|
28
28
|
begin
|
29
|
-
|
29
|
+
if liberal_parsing
|
30
|
+
csvd = CSV.read(path, encoding: encoding, liberal_parsing: true)
|
31
|
+
if encoding.to_s.downcase != "utf-8"
|
32
|
+
csv = csvd.to_a.map {|l| l.map {|cell| cell.nil? ? nil : cell.encode("utf-8", invalid: :replace, replace: '') }}
|
33
|
+
else
|
34
|
+
csv = csvd
|
35
|
+
end
|
36
|
+
|
37
|
+
encoding = "utf-8"
|
38
|
+
else
|
39
|
+
# Old style (Not Recommended)
|
40
|
+
# This "&:read" is not Yomise's function(defined avobe here).. parhaps File's method.
|
41
|
+
csv = CSV.parse(File.open(path, encoding: encoding, &:read), col_sep: col_sep)
|
42
|
+
end
|
30
43
|
rescue
|
31
44
|
# Try Another Encoding
|
32
45
|
## puts "Fail Encoding #{encoding}. Trying cp932..."
|
33
|
-
|
46
|
+
if liberal_parsing
|
47
|
+
csvd = CSV.read(path, encoding: "cp932", liberal_parsing: true)
|
48
|
+
if encoding.to_s.downcase != "utf-8"
|
49
|
+
csv = csvd.to_a.map {|l| l.map {|cell| cell.nil? ? nil : cell.encode("utf-8", invalid: :replace, replace: '') }}
|
50
|
+
else
|
51
|
+
csv = csvd
|
52
|
+
end
|
53
|
+
|
54
|
+
encoding = "UTF-8"
|
55
|
+
else
|
56
|
+
# Old style (Not Recommended)
|
57
|
+
# This "&:read" is not Yomise's function(defined avobe here).. parhaps File's method.
|
58
|
+
csv = CSV.parse(File.open(path, encoding: "cp932", &:read), col_sep: col_sep)
|
59
|
+
end
|
34
60
|
encoding = "cp932"
|
35
61
|
end
|
36
62
|
|
@@ -50,7 +76,7 @@ module Yomise
|
|
50
76
|
|
51
77
|
# Converting Encode and Setting index.. rover not supported yet
|
52
78
|
if format.to_s == "daru" || format.nil?
|
53
|
-
ans.convert_enc!(from: encoding, to: "utf-8")
|
79
|
+
ans.convert_enc!(from: encoding, to: "utf-8") if encoding.to_s.downcase != "utf-8"
|
54
80
|
begin
|
55
81
|
ans.index = ind_orig if index
|
56
82
|
rescue
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yomise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- showata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daru
|