fslaborg / Deedle

Easy to use .NET library for data and time series manipulation and for scientific programming
http://fslab.org/Deedle/
BSD 2-Clause "Simplified" License
924 stars 196 forks source link

Add util, extension and test to read a frame from a CSV string #530

Closed kMutagene closed 2 years ago

kMutagene commented 2 years ago

This PR adds a Frame extension that can read CSV from a string.

Currently, two extra steps are needed to do that: reading the bytes from the string, and passing a MemoryStream based on that to Frame.ReadCsv:

let byteArray = Encoding.UTF8.GetBytes(dataString)
use stream = new MemoryStream(byteArray)
Frame.ReadCsv(stream,true,separators=",")

Why add this?

While this saves 'only' 2 LOC in scripts, this is a common operation when getting data via HTTP requests and therefore justifies the addition IMHO. This happens often when analyzing data from online sources. Examples where i use it can be seen in the Plotly.NET docs

I added a test based on the tests already implemented. If i should add more or change something, please let m know ;)

zyzhu commented 2 years ago

Thanks for the addition. I've released 2.4.0 on nuget.