Python bucket.blob.upload“从字符串返回”;ValueError:None无法转换为unicode;

Python bucket.blob.upload“从字符串返回”;ValueError:None无法转换为unicode;,python,google-cloud-platform,google-cloud-storage,Python,Google Cloud Platform,Google Cloud Storage,我正在尝试使用以下代码行将数据帧(df)上载到云存储: bucket.blob(gcs_reference).upload_from_string(df.to_csv(index=False, encoding='utf-8'), content_type=''application/octet-stream') 但是,对于某些单元格,“我的数据帧”没有值,因此会触发错误: ValueError:无法将无转换为unicode 有没有一种方法可以超越这一点,只为None设置空值?我过去对此没有任

我正在尝试使用以下代码行将数据帧(
df
)上载到云存储:

bucket.blob(gcs_reference).upload_from_string(df.to_csv(index=False, encoding='utf-8'), content_type=''application/octet-stream')
但是,对于某些单元格,“我的数据帧”没有值,因此会触发错误:

ValueError:无法将无转换为unicode


有没有一种方法可以超越这一点,只为None设置空值?我过去对此没有任何问题,我记不起我做了什么不同。

我能够复制,它对我有效:

import pandas as pd
from gcloud import storage
client = storage.Client()

bucket = client.get_bucket('source')
d = {'col1': [1, 2], 'col2': [3, None]}
df = pd.DataFrame(data=d)

bucket.blob('file').upload_from_string(df.to_csv(index=False, encoding='utf-8'), 
content_type='application/octet-stream')
文件内容如下:

col1,col2
1,3.0
2,
或者您可以使用:

df.fillna(value=0, inplace=True)
bucket.blob('file').upload_from_string(df.to_csv(index=False, 
encoding='utf-8'), content_type='application/octet-stream')
输出文件为:

col1,col2
1,3.0
2,0.0
您的代码中包含以下部分:

 content_type=''application/octet-stream' 
这是一个语法错误

内容类型=“应用程序/八位字节流”


理想情况下,我不想填充nones,但真的将它们作为空值,也不填充None?是的,示例是不填充df