簡體   English   中英

spotfire ironpython:將新行追加到數據表

[英]spotfire ironpython : Append new row to a data-table

我有一個CSV字符串輸入
string_in="country,100,color"
任何人都可以建議我如何將此輸入(string_in)附加到現有的
在Spotfire中使用ironpython腳本進行數據表可視化。
謝謝。

您需要引入一些不同的功能,以通過腳本實現這一點。 我在下面有我的腳本,但是總體來說,您要做的是將輸入設置為數據源,然后將來自該數據源的行添加到現有的行中。 我借了一個良好的金額這個由TIBCO Spotfire中的教程,並修改了它在必要時讓我們在這里你想要的。 因此,您可能會刪除幾個多余的進口商品。

我將datTab用作腳本的輸入參數,作為要向其添加行的數據表。

from Spotfire.Dxp.Data import AddRowsSettings
import System
from System import DateTime
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin
from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings

#First we need to create your data with some columns. 
#Here I have a comma separated miniature table built up with 
#a commented option for your variable itself. \r\n used for newline
textData = "name,values,category\r\ncountry,100,color\r\n" 
#textData = "col1,col2,col3\r\n" + string_in + "\r\n"

#Memory Stream stuff. Simply just writing our variable 
#into a place we can access to make a data source
stream = MemoryStream()
writer = StreamWriter(stream)
writer.Write(textData)
writer.Flush()
stream.Seek(0, SeekOrigin.Begin)

#you need settings to tell the system what stuff you're importing.
#here we define it is comma separated and what data types our columns are.
readerSettings = TextDataReaderSettings()
readerSettings.Separator = ","
readerSettings.AddColumnNameRow(0)
readerSettings.SetDataType(0, DataType.String)
readerSettings.SetDataType(1, DataType.Integer)
readerSettings.SetDataType(2, DataType.String)
textDataSource = TextFileDataSource(stream,readerSettings)

#We create some settings here automatically having the system match
#column names for us between the data table and our data source.
settings = AddRowsSettings(datTab,textDataSource)
#And finally we add the rows from our datasource with our settings.
datTab.AddRows(textDataSource,settings)

當然,您可以使用更長的輸入變量來使其變得更加復雜,在事物之間循環以添加多行,等等。您也可以按照相同的過程,使用文件的URL代替存儲流的內容。 取決於您的輸入類型。

如果您有任何疑問,請告訴我。 我試圖對重要部分進行評論,但是如果需要,可以對特定功能進行進一步說明。

編輯:我將記錄添加了兩次之后,請參見下面的屏幕快照 截圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM