Last active
February 23, 2024 12:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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