以下是代码:
import numpy as np
import pandas as pd
def correlation(x, y):
std_x = (x - x.mean())/x.std(ddof = 0)
std_y = (y - y.mean())/y.std(ddof = 0)
return (std_x * std_y).mean
a = pd.Series([2, 4, 5, 7, 9])
b = pd.Series([12, 10, 9, 7, 3])
ca = correlation(a, b)
print(ca)
Run Code Online (Sandbox Code Playgroud)
它不返回相关的值,而是返回一个带有键的系列0 ,1, 2, 3, 4, 5和值-1.747504, -0.340844, -0.043282, -0.259691, -2.531987.
请帮我理解这背后的问题.
我正在使用Python 2.7中的以下代码片段向bigQuery加载新行分隔JSON:
from google.cloud import bigquery
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset('testGAData')
table_ref = dataset.table('gaData')
table = bigquery.Table(table_ref)
with open('gaData.json', 'rb') as source_file:
job_config = bigquery.LoadJobConfig()
job_config.source_format = 'NEWLINE_DELIMITED_JSON'
job = bigquery_client.load_table_from_file(
source_file, table, job_config=job_config)
Run Code Online (Sandbox Code Playgroud)
它返回以下错误:
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/cloud/bigquery/client.py", line 897, in load_table_from_file
raise exceptions.from_http_response(exc.response)
google.api_core.exceptions.BadRequest: 400 POST https://www.googleapis.com/upload/bigquery/v2/projects/test-project-for-experiments/jobs?uploadType=resumable: Required parameter is missing
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?我怎样才能解决这个问题?还有其他人遇到过类似的问题吗?提前致谢.编辑:添加最后一段,包括python导入并更正缩进.
google-analytics google-analytics-api python-2.7 google-bigquery google-cloud-platform