コロンが欠落している期間を修正する方法:こんにちは、みんな、
これまで経験したことのない問題が発生しました。
87列の期間(hh:mm形式)が記載されたExcelファイルがあります。
しかし、それらは hhmm または hmm にあります <-- : が欠落していることに注意してください
- 所要時間が10分未満の場合は3桁の数字で入力します(9:59は959と入力します)。
- 所要時間が9分59秒を超える場合は、4桁の数字で入力します(11分52秒の場合は1152と入力します)。
1列か2列なら対応できるが、87列となると無理だ。
添付ファイルをご覧ください。
皆様のご協力に心より感謝いたします!
乾杯、クリスチャン
自動化とスクリプト作成データ統合とデータクリーンアップRe: コロンが欠落している期間を修正する方法:選択肢はたくさんあります(これらはすべてうまくいくと思います)
1. それらをすべて文字列に変換する
2. 先頭に0を加える
3. 最後の4文字を取得します
4. 3文字目に「:」を挿入します。
5. 期間フォーマット付きの数値に変換する
Names Default To Here(1);
dt = Current Data Table();
cols = dt << Get Column Names("String");
For Each({colname}, cols,
Column(dt, colname) << Set Data Type("Character");
Eval(EvalExpr(
dt << Apply Formula(
Columns(Expr(NameExpr(AsColumn(dt, colname)))),
Formula(
s = Right("0" || Expr(NameExpr(AsColumn(dt, colname))), 4);
Left(s, 2) ||":"||Right(s,2)
),
Output("In Place")
) << Run Formulas;
));
);
For Each({colname}, cols,
Column(dt, colname) << Set Data Type(Numeric, Format("hr:m", 30), Input Format("hr:m")) << Set Modeling Type("Continuous");
);
または
Names Default To Here(1);
dt = Current Data Table();
cols = dt << Get Column Names("String");
dt << Begin Data Update;
For Each({colname}, cols,
For Each Row(dt,
s = Char(Column(dt, colname)[]);
If(Column(dt, colname)[] < 1000,
s = "0" || s
);
Column(dt, colname)[] = In Format(Left(s, 2) || ":" || Right(s, 2), "hr:m");
);
Column(dt, colname) << Format("hr:m", 30);
);
dt << End Data Update;
または、数値をそのまま使用して、JMP時間形式に「変換」します。
Names Default To Here(1);
dt = Current Data Table();
cols = dt << Get Column Names("String");
dt << Begin Data Update;
For Each({colname}, cols,
For Each Row(dt,
val = Column(dt, colname)[];
h = Floor(val / 100);
m = Mod(val, 100);
t = h * In Hours(1) + m * In Minutes(1);
Column(dt, colname)[] = t;
);
Column(dt, colname) << Format("hr:m", 30);
);
dt << End Data Update;
Re: コロンが欠落している期間を修正する方法:そして最後の方法は、JMPから対話的に実行することも非常に簡単です。
1. すべての列を選択します
2. 列ヘッダーを右クリックします
3. 数式クイック列を作成する
4. 相対スタイルを使用して数式を置き換えます
h = Floor(_relative_from_Col 1 / 100);
m = Mod(_relative_from_Col 1, 100);
t = h * In Hours(1) + m * In Minutes(1);
5. 出力をインプレースデータに変更する

6. 「xを置換」をクリックします。
7. 標準属性を使用して、フォーマットを時間:分に変更します。現状では、最適なフォーマットで秒数しか表示されていません。

8. [OK]または[適用]をクリックした後

そしてJMPは、スクリプトを自動で作成してくれるのでとても便利です。
// Transform column
Data Table("example for JMP com") << Apply Formula(
Columns(Group(:Col 1, 2), Ref("_relative_from_Col 1")),
Formula(
h = Floor(_relative_from_Col 1 / 100);
m = Mod(_relative_from_Col 1, 100);
t = h * In Hours(1) + m * In Minutes(1);
),
Output("In Place")
) << Run Formulas;
// Standardize column attributes
Local({old dt = Current Data Table()},
Current Data Table(Data Table("example for JMP com"));
For Each({col, index}, {:Col 1, :Col 2}, col << Format("hr:m", 10));
Current Data Table(old dt);
);
Re: コロンが欠落している期間を修正する方法:私ならこうします。
Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column names( contiuous, string );
For Each( {col}, colNames,
Show( col );
For Each Row(
As Column( col ) = Informat(
Substr( Char( As Column( Col ) ), 1, Length( Char( As Column( Col ) ) ) - 2 ) || ":" ||
Substr( Char( As Column( Col ) ), Length( Char( As Column( Col ) ) ) - 1, 2 ),
"hr:m"
)
);
column(dt,col) << format( "hr:m" );
);
Re: コロンが欠落している期間を修正する方法:こんにちは、Jarmoさん、本当にありがとうございます!
最初の脚本が魔法のように効果を発揮する!
ただ、時々、時間がhh:mm:ssの形式で入力されていることに今気づいた。
これを回避する方法はありますか?例v2を参照してください。
乾杯、C
追伸:次に会った時は、コーヒーかビールをご馳走しますね!
Re: コロンが欠落している期間を修正する方法:もしそれが実際のデータ(異なる形式の文字列)から得られたものであれば、元の例では数値データだったはずです。例にあるように、秒数は常に00なのでしょうか?
Re: コロンが欠落している期間を修正する方法:はい、残念ながらこれは実際のデータに基づいています。
この問題のない2つの列を選択していたので、recodeを使えば済むと思っていました。
しかし、私の考えは間違っていた、あるいは少なくとも、84列に対してrecodeを使うのは自分の手に負えないほど過酷だと気づいた。
はい、秒数は常に00です。
Re: コロンが欠落している期間を修正する方法:列が文字型列の場合のクイック数式メソッドの数式。この数式は、既に期間が「フォーマット」されている値には、時間部分にゼロ埋め(例: 0 9:00:00)が設定されていることを前提としています。
numonly = Substitute(_relative_from_X__1, ":", ""); // remove ":"
hrm = Left(numonly, 4); // take 4 characters from left
val = Num(hrm); // convert to numeric for calculations
h = Floor(val / 100); // take only hundreds
m = Mod(val, 100); // remainder
t = h * 60*60 + m * 60; // convert to seconds

ここで新しい列を作成することで、開始時点のデータと簡単に比較できます。数式を作成した後、標準化属性(データ型、モデリングタイプ、フォーマット)を使用して必要な型変更を行います。

もっと見る...
This will create new data columns, you might want to use in place data instead
// Transform column
Data Table("example for JMP com v2") << Apply Formula(
Columns(Group(:X__1, 12), Ref("_relative_from_X__1")),
Formula(
numonly = Substitute(_relative_from_X__1, ":", "");
hrm = Left(numonly, 4);
val = Num(hrm);
h = Floor(val / 100);
m = Mod(val, 100);
t = h * 60 * 60 + m * 60;
),
Output(New Static)
) << Run Formulas;
// Standardize column attributes
Local({old dt = Current Data Table()},
Current Data Table(Data Table("example for JMP com v2"));
For Each({col, index},
{:X__1 2, :X__2 2, :X__3 2, :X__4 2, :X__5 2, :X__6 2, :X__7 2, :X__8 2,
:X__9 2, :X__10 2, :X__11 2, :X__12 2},
col << Set Data Type(Numeric, Format("Best", 12))
);
Current Data Table(old dt);
);
// Standardize column attributes
Local({old dt = Current Data Table()},
Current Data Table(Data Table("example for JMP com v2"));
For Each({col, index},
{:X__1 2, :X__2 2, :X__3 2, :X__4 2, :X__5 2, :X__6 2, :X__7 2, :X__8 2,
:X__9 2, :X__10 2, :X__11 2, :X__12 2},
col << Set Modeling Type("Continuous")
);
Current Data Table(old dt);
);
// Standardize column attributes
Local({old dt = Current Data Table()},
Current Data Table(Data Table("example for JMP com v2"));
For Each({col, index},
{:X__1 2, :X__2 2, :X__3 2, :X__4 2, :X__5 2, :X__6 2, :X__7 2, :X__8 2,
:X__9 2, :X__10 2, :X__11 2, :X__12 2},
col << Format("hr:m", 12)
);
Current Data Table(old dt);
);