根据现有数据创建新列我有一个大型数据集,其中一列数据包含具有以下格式的单元格。有没有一种方法可以将不同的“ AppNames”提取到3个单独的列中。我已经尝试过在实用工具中使用“文本到列”功能,但是并非列中的所有单元格都列出了一个以上的应用程序名称,否则它们可能包含的信息略有不同,从而导致对齐失败,最终导致新列中的值不正确…理想情况下,我可以使用'AppName:'字符串作为'定界符'吗?因此,从下面的示例中...我应该以三个新列结尾-数据引用了Application1,Application2和Application3 ...谢谢
格式
tx:AppID:32734,tx: 应用名称:Application1 ,tx:ServerEnv:Development,tx:ServerStatus:Deployed,tx:OwningVP:xxxxxxxxx,tx:DevMgr:xxxxxxxxx,tx:OwningDirector:xxxxxxxxx,tx:AppOwner:xxxxxxxxx,tx:BusinessOwner:xxxxxxxxx,tx:SOX:No,tx :PCI:否,tx:L5_MGR:xxxxxxxxx,tx:DataClass:内部使用,tx:DRClass:Class I,tx:AppType:IT支持,tx:OrgL2:TSO,tx:OrgL3:TMX,tx:OrgL4:Mobile和VC,tx:AppID:655369,tx: AppName:Application2 ,tx:OwningVP:xxxxxxxx,tx:DevMgr:xxxxxxxx,tx:OwningDirector:xxxxxxxx,tx:AppOwner:xxxxxxxx,tx:BusinessOwner:xxxxxxxxx,tx:SOX:KFS Tier 2,tx :: KBA Tier 1,tx:DataClass:受限,tx:OrgL2:CBS,tx:OrgL3 :, tx:tx:AppID:655364,tx: 应用名称:Application3
回复:从现有数据中创建新列对于您的问题,我采取了一些不同的方法。 在查看数据时,我意识到您拥有许多不同的列,其中行是应用程序。 所以我写了一个小脚本,将所有内容分解。 现在的问题是,数据中有错误。 因此,我在代码中添加了尝试修复它们的区域。 由于没有您的所有数据,我确信可能需要添加更多修复程序。 输入这些数据后,如果您仍然希望将数据对齐3列,则可以轻松地将数据转置为3列。
Names Default To Here( 1 );
theData =
"tx:AppID:32734, tx:AppName:Application1, tx:ServerEnv:Development, tx:ServerStatus:Deployed, tx:OwningVP:xxxxxxxxx, tx:DevMgr:xxxxxxxxx, tx:OwningDirector:xxxxxxxxx, tx:AppOwner:xxxxxxxxx, tx:BusinessOwner:xxxxxxxxx, tx:SOX:No, tx:PCI:No, tx:L5_MGR:xxxxxxxxx, tx:DataClass:Internal Use, tx:DRClass:Class I, tx:AppType:IT Supported, tx:OrgL2:TSO, tx:OrgL3:TMX, tx:OrgL4:Mobile and VC, tx:AppID:655369, tx:AppName:Application2, tx:OwningVP:xxxxxxxx, tx:DevMgr:xxxxxxxx, tx:OwningDirector:xxxxxxxx, tx:AppOwner:xxxxxxxx, tx:BusinessOwner:xxxxxxxxx, tx:SOX:KFS Tier 2, tx::KBA Tier 1, tx:DataClass:Restricted, tx:OrgL2:CBS, tx:OrgL3:, tx: tx:AppID:655364, tx:AppName:Application3";
dt = New Table( "The Table" );
dt << delete columns( "Column 1" );
word# = 1;
While( Word( word#, theData, "," ) != "",
colNameList = dt << get column names( string );
theWord = trim(Word( word#, theData, "," ));
// Make found corrections
If( Trim( Word( 2, theWord, ":" ) ) == "tx",
theword = Word( 2, theword, ":" ) || ":" || Word( 3, theWord, ":" ) || ":" || Word( 4, theWord, ":" )
);
If( word( 1, theWord, ":") == "", theWord = "tx" || theWord );
if( word( 2, theWord, ":") == "",
theword = Word( 1, theword, ":" ) || ":" || word(1,Word( 3, theWord, " " )," ") || ":" ||
substr(Word( 3, theWord, ":" ),length(Word( 3, theWord, ":" ))+2);
);
if( word( 3, theWord, ":") == "",
theword = Word( 1, theword, ":" ) || ":" || word(1,Word( 2, theWord, ":" )," ") || ":" ||
substr(Word( 2, theWord, ":" ),length(Word( 1, Word( 2, theWord, ":" ), " " ))+2);
);
if(word(2,theword,":")=="KBA",show(theword));
colName = Word( 2, theWord, ":" );
If( Word( 2, theWord, ":" ) == "AppID",
dt << Add Rows( 1 );
);
If( N Rows( Loc( colNameList, colName ) ) == 0,
dt << New Column( colName, character );
);
Column( dt, colName )[N Rows( dt )] = Word( 3, theWord, ":" );
word#++;
);
回复:从现有数据中创建新列谢谢吉姆...我想我要做的是从“资产标签”列中提取“ AppName”数据,然后将其放入新列中(应用程序1、2、3)。请参见下面的屏幕截图。
(AppName:Exchange 2013(350578)来自下面第1行的资产标签)
“资产标签”列中的某些行包含多个AppName,但不幸的是,它们并不统一,请参见以下示例:
示例1格式 (1个AppName)
tx:AppID:350578,tx: 应用名称:Exchange 2013(350578), tx:ServerEnv:生产,tx:ServerStatus:维护中,tx:OwningVP:xxxxxxxxx,tx:DevMgr:xxxxxxxxx,tx:OwningDirector:xxxxxxxxx,tx:AppOwner:xxxxxxxxx,tx:BusinessOwner:xxxxxxxxx,tx:SOX:否,tx :PCI:否,tx:L5_MGR:xxxxxxxxx,tx:EMEABanking:KBA Tier 2,tx:DataClass:Highly Restricted,tx:DRClass:Class I,tx:AppType:IT Supported,tx:OrgL2:TSO,tx:OrgL3: TMX,tx:OrgL4:消息传递和内容管理
示例2格式 (3个应用名称)
tx:AppID:32734,tx: 应用名称:CITRIX(32734) ,tx:ServerEnv:Development,tx:ServerStatus:Deployed,tx:OwningVP:XXXXXXXXX,tx:DevMgr:XXXXXXXXX,tx:OwningDirector:XXXXXXXXX,tx:AppOwner:XXXXXXXXX,tx:BusinessOwner:XXXXXXXXX,tx:SOX:No,tx :PCI:否,tx:L5_MGR:XXXXXXXXX,tx:EMEABanking:KBA Tier 2,tx:DataClass:内部使用,tx:DRClass:I类,tx:AppType:IT支持,tx:OrgL2:TSO,tx:OrgL3: TMX,tx:OrgL4:移动和VC,tx:AppID:655369,tx: 应用名称:EBOSS EMEA(655369) ,tx:OwningVP:XXXXXXXXX,tx:DevMgr:XXXXXXXXX,tx:OwningDirector:XXXXXXXXX,tx:AppOwner:XXXXXXXXX,tx:BusinessOwner:XXXXXXXXX,tx:SOX:KFS Tier 2,tx:L5_MGR:XXXXXXXXX,tx:EMEABanking:XXX层1,tx:DataClass:Restricted,tx:OrgL2:CBS,tx:OrgL3:Dell Financial SVCS,tx:OrgL4:DFS起源和租赁服务,tx:AppID:655364,tx: AppName:TVALUE(655364)
示例3格式 (1个AppName,但格式不同)
分机: AppName:电压 ,ext:PCI:N,ext:OrgL3:TMX,ext:L5_Mgr:xxxxxxxxx,ext:Owning_Director:xxxxxxxxx,ext:App_Owner:xxxxxxxxx,ext:Owning_Group:消息传递和内容管理,Dell外部,外部,高级,禁止的服务,DC扫描-外部,tx:AppID:2812,tx:AppName:Exchange 2010,tx:ServerEnv:Production,tx:ServerStatus:Deployed,tx:OwningVP:xxxxxxxxx,tx:DevMgr:xxxxxxxxx,tx:OwningDirector:xxxxxxxxx,tx: AppOwner:xxxxxxxxx,tx:BusinessOwner:xxxxxxxxx,tx:SOX:否,tx:PCI:否,tx:L5_MGR:xxxxxxxxx,tx:EMEABanking:否,tx:DataClass:高度受限,tx:DRClass:I类,tx: AppType:支持的IT,tx:OrgL2:TSO,tx:OrgL3:TMX,tx:OrgL4:消息传递和内容管理
注意:下面的“应用程序#1”列是通过“列>实用工具...”中的“文本到列”功能创建的。
不知道是否解释得很好;-(

回复:从现有数据中创建新列我相信这段代码会做您想要的。 随附的是数据表,其中包含您提供的示例的3行。 下面的脚本处理多个应用程序提取
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "Application #1", character );
dt << New Column( "Application #2", character );
dt << New Column( "Application #3", character );
For( theRow = 1, theRow <= N Rows( dt ), theRow++,
word# = 1;
appName# = 1;
While( Word( word#, :Asset Tags[theRow], "," ) != "",
theWord = Trim( Word( word#, :Asset Tags[theRow], "," ) );
If( Word( 2, theWord, ":" ) == "AppName",
Column( dt, "Application #" || Char( appName# ) )[theRow] = Word( 3, theWord, ":" );
appName#++;
);
word#++;
);
);
回复:从现有数据中创建新列这是一种稍微不同的方法,包括将值添加到表中。 我在代码顶部有一个解析函数,类似于话 ,但定界符可以是多个字符。
//------------------------------------------------------------------------------
/*
Function Name: my_parse
Description: Parse text according to a given delimiter. Two delimiters in a row
will yield an empty list entry, which is different from the behavior
of WORDS
Returns: list of tokens
Arguments:
_text Text to determine be parsed
_delim Delimiter
*/
my_parse = function({_text, _delim},
{Default Local},
pname = "get_words";
if (is missing(_text),
// then
ret_list = {};
,
// else if
_text == "",
ret_list = {};
,
// else we've got some text to work with
ret_list = {};
len_delim = length(_delim);
istart = 1;
keep_going = 1;
while (keep_going,
iend = contains(_text, _delim, istart);
if (!iend,
keep_going = 0;
insertinto(ret_list, substr(_text, istart), 1);
,
insertinto(ret_list, substr(_text, istart, (iend - istart)), 1);
istart = iend + len_delim;
);
);
);
reverse(ret_list);
); // end my_parse
//------------------------------------------------------------------------------
dt = current data table();
dt << new column("Application #1", character);
dt << new column("Application #2", character);
dt << new column("Application #3", character);
for(i = 1, i <= nrows(dt), i++,
one_asset = dt:asset tags[i];
one_list = my_parse(one_asset, ", ");
app_list = {};
m = 0;
for (k = 1, k <= nitems(one_list), k++,
one_item = one_list[k];
aloc = contains(one_item, "AppName:");
if (aloc,
m++;
app_list[m] = substr(one_item, 8 + aloc);
);
);
show(app_list);
// Now add these to the respective Application # columns
for (k = 1, k <= nitems(app_list), k++,
cname = "Application #" || char(k);
column(dt, cname)[i] = app_list[k];
);
);