根據現有數據創建新列我有一個大型數據集,其中一列數據包含具有以下格式的單元格。有沒有一種方法可以將不同的“ 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];
);
);