Skip to content

from_csv via String #534

Description

@reedjosh

Feature Request
I get csv output from a command. I would like a way to give Daru.from_csv a csv string for parsing instead of a path.

In Pandas I do:

pd.read_csv(StringIO(results.stdout))

I don't know if StringIO is do-able for Daru.from_csv, but I'm working around it now via:

def csv_string_to_df(csv_str)
	csv_as_arrays = ::CSV.parse(csv_str)
	headers = csv_as_arrays.shift
	csv_as_arrays = csv_as_arrays.transpose

	hsh = {}
	headers.each_with_index do |h, i|
  	hsh[h] = csv_as_arrays[i]
	end
	Daru::DataFrame.new(hsh)
end

I kind of think that if you just attempted to read the file first and then gave that to CSV.parse then I could use ruby's StringIO in place of a path since it would be read outside of the CSV lib.

Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions