I am trying to upload a pandas dataframe as a csv to Google Cloud Storage. The code has to upload the content of the dataframe regardless of the characters it contains.
The problem I have is that when the frame contains special characters, such as Japanese symbols, Google returns an error that is difficult to interpret:
Exception: Failed to process HTTP response.
The code itself is the following:
import datalab.storage as gcs
import pandas as pd
Items_Object = gcs.Bucket('astrologer-2').items(prefix=file_prefix)
for item in items:
if not item.key.endswith('/') and item.exists():
data = StringIO(item.read_from())
dataFrame = pd.read_csv(data, low_memory=False, sep=',', encoding='utf-8')
df_string = dataFrame.to_csv(index=False, encoding='utf-8')
print df_string
response = item.write_to(df_string, 'text/csv')
The error fires on the line item.write_to(df_string, 'text/csv').
All the code does is reading a CSV and trying to write its content back to Google Cloud Storage (in the future there will be changes made to the content)
The content of the file is
Nombre,Apellido
Lluís,Gassó
Test,Testson
最高,サートした
I tried using 'text/plain', 'text/plain;encoding=UTF-8', 'text/csv;encoding=UTF-8' and 'application/octet-stream' and none of them worked.
Does anyone know why is this error happening and how can it be fixed? Thanks in advance.