我是Deedle的新手,在文档中我找不到如何解决我的问题。
我使用以下代码将SQL Table绑定到Deedle Frame:
namespace teste
open FSharp.Data.Sql
open Deedle
open System.Linq
module DatabaseService =
[<Literal>]
let connectionString = "Data Source=*********;Initial Catalog=*******;Persist Security Info=True;User ID=sa;Password=****";
type bd = SqlDataProvider<
ConnectionString = connectionString,
DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER >
type Database() =
static member contextDbo() =
bd.GetDataContext().Dbo
static member acAgregations() =
Database.contextDbo().AcAgregations |> Frame.ofRecords
static member acBusyHourDefinition() =
Database.contextDbo().AcBusyHourDefinition
|> Frame.ofRecords "alternative_reference_table_scan", "formula"]
static member acBusyHourDefinitionFilterByTimeAgregationTipe(value:int) =
Database.acBusyHourDefinition()
|> Frame.getRows这些东西工作正常,因为我不能理解Data Frame Schema,令我惊讶的是,这不是表的表示。
我的问题是:
如何按行而不是按列访问我的数据库元素(列是Deedle的默认值)?我想了一下文档中显示的内容,但不幸的是,列的名称无法识别,就像在the CSV example in Deedle Website中一样。
发布于 2016-07-30 09:50:46
使用Frame.ofRecords,您可以将表提取到数据帧中,然后对其行或列进行操作。在本例中,我有一个非常简单的表。这是针对SQL Server的,但我假设MySQL也会有同样的效果。如果您在问题中提供更多详细信息,则可以缩小解决方案的范围。
这是按ID编制索引的表,ID为Int64:

您可以使用行或列:
#if INTERACTIVE
#load @"..\..\FSLAB\packages\FsLab\FsLab.fsx"
#r "System.Data.Linq.dll"
#r "FSharp.Data.TypeProviders.dll"
#endif
//open FSharp.Data
//open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Deedle
[<Literal>]
let connectionString1 = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\userName\Documents\tes.sdf.mdf"
type dbSchema = SqlDataConnection<connectionString1>
let dbx = dbSchema.GetDataContext()
let table1 = dbx.Table_1
query { for row in table1 do
select row} |> Seq.takeWhile (fun x -> x.ID < 10L) |> Seq.toList
// check if we can connect to the DB.
let df = table1 |> Frame.ofRecords // pull the table into a df
let df = df.IndexRows<System.Int64>("ID") // if you need an index
df.GetRows(2L) // Get the second row, but this can be any kind of index/key
df.["Number"].GetSlice(Some 2L, Some 5L) // get the 2nd to 5th row from the Number column将得到以下输出:
val it : Series<System.Int64,float> =
2 -> 2
>
val it : Series<System.Int64,float> =
2 -> 2
3 -> 3
4 -> 4
5 -> 5 根据您正在尝试做的事情,Selecting Specific Rows in Deedle可能也会起作用。
编辑
从你的评论来看,你似乎正在处理一些大的表格。根据您有多少内存和表的大小,您仍然可以加载它。如果不是,以下是您可以在增加复杂性的情况下执行的一些操作:
query { } expression来缩小数据库服务器上的数据集,并只将结果的一部分转换为数据帧。您可以进行非常复杂的转换,因此您最终可能甚至不需要数据帧。这基本上就是Linq2Sql。https://stackoverflow.com/questions/38667991
复制相似问题