数据集SQL的预处理
我有一个包含 100 行和 2001 个属性的数据集的平面文件,如下所示:
att1,att2,att4,att5,att6,att7,att8,att9,att10,....,att2000,type
5,3,4,4,1,5,1,3,2,4,...,12,Agresti
4,4,2,0,1,0,2,0,0,0,...,22,bbresti
0,0,0,0,0,0,0,0,1,0,...,34,bbresti
0,0,0,1,0,0,0,1,1,1,...,45,Agresti
...
0,6,0,0,0,0,1,0,3.5,...,1,Agresti
我想将此数据预处理为
i,j,val
1,1,5
1,2,4
1,3,0
1,4,0
...
1,100,0
2,1,3
2,2,4
2,3,0
2,4,0
...
2,100,6
3,1,4
3,2,2
3,3,0
3,4,0
...
...
2000,100,1
所以我摆脱了最后一个列类型,我知道在 sql 中我会做类似的事情:
CREATE TABLE matrix (Row int NOT NULL, Column int NOT NULL, Value <datatype> NOT NULL)
SELECT Row AS Column
,Column AS Row
,Value
FROM matrix
但是当我只想在 SQL 中导入表,但是 C# 中的代码是什么样的
I have a flat file of a dataset with 100 rows and 2001 attributes like this:
att1,att2,att4,att5,att6,att7,att8,att9,att10,....,att2000,type
5,3,4,4,1,5,1,3,2,4,...,12,Agresti
4,4,2,0,1,0,2,0,0,0,...,22,bbresti
0,0,0,0,0,0,0,0,1,0,...,34,bbresti
0,0,0,1,0,0,0,1,1,1,...,45,Agresti
...
0,6,0,0,0,0,1,0,3.5,...,1,Agresti
And I would like to preprocess this data as
i,j,val
1,1,5
1,2,4
1,3,0
1,4,0
...
1,100,0
2,1,3
2,2,4
2,3,0
2,4,0
...
2,100,6
3,1,4
3,2,2
3,3,0
3,4,0
...
...
2000,100,1
So i get rid of the last column type, I kmow that in sql I would do something like:
CREATE TABLE matrix (Row int NOT NULL, Column int NOT NULL, Value <datatype> NOT NULL)
SELECT Row AS Column
,Column AS Row
,Value
FROM matrix
But as I would like to just import the table in SQL, but How does the code look like in c#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一些 C# 的想法,它将获取您的输入文件并重新格式化您所请求的格式。然后使用 SqlBulkCopy 类将数据推送到 SQLServer 中的表中。
希望有帮助。
Here's an idea of some C# that will take your input file and reformat you're requesting. Then use the SqlBulkCopy class to push your data up into a table in SQLServer.
Hope it helps.