def save_csv_to_cloud_storage(df,file_name,folder='output'):
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/Users/******/Desktop/*****.json'
storage_client = storage.Client()
bucket = storage_client.get_bucket('fluxlengow')
now = datetime.now()
dt_string = now.strftime("%Y%m%d-%H%M%S")
f = StringIO()
df.to_csv(f,sep=',')
f.seek(0)
Blob('{}/{}_{}_.csv'.format(folder, dt_string, file_name),bucket).upload_from_file(f,content_type='text/csv')
def lengowToStorage():
liste = ['https://httpnas.****.*****/******/SUP****/*******_FR.csv','https://httpnas.****.*****/******/SUP****/*******_UK.csv','https://httpnas.****.*****/******/SUP****/*******_IT.csv']
for i in liste :
name = i.split('/')[-1]
name = name.split('.')[0]
CSV_URL = '{}'.format(i)
with requests.Session() as s:
download = s.get(CSV_URL)
decoded_content = download.content.decode('utf8')
cr = csv.reader(decoded_content.splitlines(), delimiter='|')
my_list = list(cr)
df_ = pd.DataFrame(my_list, columns=my_list[0]).drop(0)
save_csv_to_cloud_storage(df_,file_name=name,folder='input')
print("recuperation du fichier : {}".format(i))
lengowToStorage()
Hi guys , I'm sorry but I need your help because I'm really stuck on this encoding issue. I'm trying to send my dataframe to cloud storage as a CSV file. unfortunately when i try to save it to storage i get this error
'latin-1' codec can't encode character '\u2019' in position 32318: Body ('’') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
I then did the "utf-8" encoding on each columns (not shown in the code) and the saving to Cloud Storage does work but my data are into this format :
b'Antaeus Lotion Apr\xc3\xa8s Rasage 100ml'
I decode UTF8, I encode UTF8 ... but can't get my data into the string version I want...
'Antaeus Lotion Après Rasage 100ml'
If you could help , Id be very greatful