Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google电子表格到Google Drive中的CSV_Python_Pandas_Google Sheets_Drive - Fatal编程技术网

Python Google电子表格到Google Drive中的CSV

Python Google电子表格到Google Drive中的CSV,python,pandas,google-sheets,drive,Python,Pandas,Google Sheets,Drive,将CSV文件上载到Google drive时,它会自动转换为Google工作表。如何将其保存为驱动器中的CSV文件?或者我可以通过熊猫数据框阅读谷歌工作表吗 开发环境:googlecolab 代码片段: 输入 data = pd.read_csv("ner_dataset.desktop (3dec943a)", encoding="latin1").fillna(method="ffill") data.tail(10) [Desktop Entry] 0 Type=Link

将CSV文件上载到Google drive时,它会自动转换为Google工作表。如何将其保存为驱动器中的CSV文件?或者我可以通过熊猫数据框阅读谷歌工作表吗

开发环境:googlecolab

代码片段

输入

data = pd.read_csv("ner_dataset.desktop (3dec943a)", 
encoding="latin1").fillna(method="ffill")

data.tail(10)
    [Desktop Entry]
0   Type=Link
1   Name=ner_dataset
2   URL=https://docs.google.com/spreadsheets/d/1w0...
输出

data = pd.read_csv("ner_dataset.desktop (3dec943a)", 
encoding="latin1").fillna(method="ffill")

data.tail(10)
    [Desktop Entry]
0   Type=Link
1   Name=ner_dataset
2   URL=https://docs.google.com/spreadsheets/d/1w0...

工作代码

from google.colab import auth
auth.authenticate_user()

import gspread
from oauth2client.client import GoogleCredentials

gc = gspread.authorize(GoogleCredentials.get_application_default())

worksheet = gc.open('Your spreadsheet name').sheet1

# get_all_values gives a list of rows.
rows = worksheet.get_all_values()
print(rows)

# Convert to a DataFrame and render.
import pandas as pd

pd.DataFrame.from_records(rows)

这可能会对您有所帮助:gspread.readthedocs.io/en/latest谢谢您的回复。下面的代码对我有用从google.colab导入auth auth.authenticate_user()从oauth2client.client导入gspread导入GoogleCredentials gc=gspread.authorize(GoogleCredentials.get_application_default())工作表=gc.open('您的电子表格名称')。sheet1#get_all_值提供行列表。行=工作表。获取所有值()打印(行)#转换为数据帧并渲染。导入pandas作为pd.DataFrame.from_records(rows)`@Phani,您可以回答自己的问题,寻找代码的人可能会有所帮助。你可以粘贴下来。感谢您使用堆栈溢出