Skip to content

Instantly share code, notes, and snippets.

@salvadorgascon
Last active February 23, 2024 12:46
Show Gist options
  • Save salvadorgascon/4e7a16392a1743e036ce60bc2b174826 to your computer and use it in GitHub Desktop.
Save salvadorgascon/4e7a16392a1743e036ce60bc2b174826 to your computer and use it in GitHub Desktop.
Python transformer to convert a string containing CSV data into a Panda Object
import datetime
import os
from pandas import read_csv
def CsvDataframeTransformer(csv_string, tmp_path):
print("Reading CSV")
filename = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
print("Saving CSV into", tmp_path+'/'+filename+'.csv')
with open(tmp_path+'/'+filename+'.csv', 'w') as f:
f.write(csv_string)
print("Parsing CSV", tmp_path+'/'+filename+'.csv')
panda_object = read_csv(tmp_path+'/'+filename+'.csv')
print("Removing CSV", tmp_path+'/'+filename+'.csv')
os.remove(tmp_path+'/'+filename+'.csv')
return panda_object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment