请参考下面的回答,希望对你有帮助。
import pandas as pd
data = [['Alex','Feb',10],['Bob','jan',12]]
df = pd.DataFrame(data,columns=['Name','Month','Age'])
print df
Output
Name Month Age
0 Alex Feb 10
1 Bob jan 12
添加一行
row = ['Sally','Oct',15]
df.loc[len(df)] = row
print df
output
Name Month Age
0 Alex Feb 10
1 Bob jan 12
2 Sally Oct 15
使用 gsutil 写入/复制到 GCP 存储桶
df.to_csv('text.csv', index = False)
!gsutil cp 'text.csv' 'gs://BucketName/folderName/'
Python 代码(文档https://googleapis.dev/python/storage/latest/index.html https://googleapis.dev/python/storage/latest/index.html )
from google.cloud import storage
def upload_to_bucket(bucket_name, blob_path, local_path):
bucket = storage.Client().bucket(bucket_name)
blob = bucket.blob(blob_path)
blob.upload_from_filename(local_path)
return blob.url
# method call
bucket_name = 'bucket-name' # do not give gs:// ,just bucket name
blob_path = 'path/folder name inside bucket'
local_path = 'local_machine_path_where_file_resides' #local file path
upload_to_bucket(bucket_name, blob_path, local_path)