在Colab研究中使用python从Google电子表格中绘制文件

时间:2019-12-30 01:12:41

标签: python-3.x pandas

我追求两个目标:

我想阅读Google电子表格中的第1列和第2列表单文件: https://docs.google.com/spreadsheets/d/1p8agnxX2Fm7SF-u_NygcxDDLWP6C-7gEUnhmb7uWzIM/edit?usp=sharing

绘制第1列和第2列

我输入了此代码https://colab.research.google.com/drive/1DDtP-Bs5TzZzrmbLcqJaEoH3JGQct21D

from google.colab import drive
drive.mount("/content/gdrive", force_remount=True)
#instal package spreadsheet google
!pip install --upgrade --quiet gspread
# Import library autentific and create interfaz for spreadsheet google
#it will generate a authorization code
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gc = gspread.authorize(GoogleCredentials.get_application_default())
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline 
import numpy as np
import math 
#change to home directory
%cd /content/gdrive/My\ Drive/
worksheet = gc.open('lawrence_ODto8e15').sheet1
#worksheet = gc.open('data_set.csv').sheet1
rows = worksheet.get_all_values()
OD = pd.DataFrame.from_records(rows)

y=OD[:,1]
x=OD[:,0]

plt.plot(x, y,'b--',  label= "plot")

我遇到下一个错误

(错误提示)

TypeError Traceback(最近一次调用最后一次)()5 OD = pd.DataFrame.from_records(rows)6 ----> 7 y = OD [:,1] 8 x = OD [:,0] 9

get_loc中的2帧/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py(self,key,method,tolerance)2895)2896试试:-> 2897 return self ._engine.get_loc(key)2898,但KeyError:2899返回self._engine.get_loc(self._maybe_cast_indexer(key))

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

TypeError:'(slice(None,None,None),1)'是无效的密钥

感谢您的帮助

谢谢

0 个答案:

没有答案