在gpython中删除标题

时间:2019-05-15 16:45:30

标签: pandas pandas-datareader pygsheets

我创建了一个Google电子表格,然后成功导入了python。当我尝试转换为数据框时,我无法重命名其索引。

SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']

# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = '1wLBJaIxIQ9QW2XRnnqt_UzzWMQ03AJBI1EENGbDuq0k'
SAMPLE_RANGE_NAME = 'Sheet1'

"""Shows basic usage of the Sheets API.Prints values from a sample spreadsheet."""
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
         creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server()
        # Save the credentialsfor the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

service = build('sheets', 'v4', credentials=creds)

    # Call the Sheets API
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,range=SAMPLE_RANGE_NAME).execute()
values = result.get('values')
df=pd.DataFrame(values)
df=pd.DataFrame(values, index_col="Date", parse_dates=True)

在第二个命令行中,当我尝试将值转换为上述代码的DataFrame时,然后确定并提供以下结果。

Out[28]
            0       1       2
0        Date     ABC     ACB
1   5/15/2019  179358  183382
2   5/16/2019  153780   72424
3   5/17/2019  205207  201512
4   5/18/2019  101620  155624
5   5/19/2019   53838  136139

但是当我尝试输入最后一行代码时,它给了我以下错误。

df=pd.DataFrame(values,index_col="Date",parse_dates=True)
Traceback (most recent call last):

  File "<ipython-input-31-ea38c8aca02c>", line 1, in <module>
    df=pd.DataFrame(values,index_col="Date",parse_dates=True)

TypeError: __init__() got an unexpected keyword argument 'index_col'

0 个答案:

没有答案