I am working on “everything python” in the ghhops-server with flask for an app in grasshopper canvas. Hitting a wall with importing/reading csv files and outputting dataframes or series data on the grasshopper canvas. Any help would be most appreciated. Michael Wickerson
I figured out the first part for the inputs but I am still trying to figure out how to “output” data from dataframes, series, arrays, etc…, into the grasshopper canvas. Perhaps I should use HopsString on the outputs as well. Any help would be most appreciated. Michael wickeson
From my small experience with hops, I think you want to return the csv as a string with a custom separator to pass it between grasshopper components (I remember having problems when using default separators for some reasons).
Here under is a function to read csv and put it back in a dataframe (with a custom separator and some options)
def csv_to_df(df1):
"""load df from a csv, with special line-terminator"""
buffer = io.StringIO(df1)
loaded_df1 = pd.read_csv(filepath_or_buffer=buffer, skipinitialspace=True, lineterminator='@')
return loaded_df1
Then whenever you’ve done what you needed with your DF, you need to convert it back to a csv, with the same custom separator