Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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 在Kaggle'中设置了max#u results值和to#u数据帧的列表#u行出现问题;s";SQL简介;课程_Python_Google Bigquery_Kaggle - Fatal编程技术网

Python 在Kaggle'中设置了max#u results值和to#u数据帧的列表#u行出现问题;s";SQL简介;课程

Python 在Kaggle'中设置了max#u results值和to#u数据帧的列表#u行出现问题;s";SQL简介;课程,python,google-bigquery,kaggle,Python,Google Bigquery,Kaggle,我需要一些帮助。在第1部分中,我遇到了以下问题。我在[7]中已经讲到: # Preview the first five lines of the "full" table client.list_rows(table, max_results=5).to_dataframe() 我得到了一个错误: getting_started_with_bigquery.py:41: UserWarning: Cannot use bqstorage_client if max_res

我需要一些帮助。在第1部分中,我遇到了以下问题。我在[7]中已经讲到:

# Preview the first five lines of the "full" table
client.list_rows(table, max_results=5).to_dataframe()
我得到了一个错误:

getting_started_with_bigquery.py:41: UserWarning: Cannot use bqstorage_client if max_results is set, reverting to fetching data with the tabledata.list endpoint.
  client.list_rows(table, max_results=5).to_dataframe()
我正在用Notepad++编写代码,然后在Windows的命令提示符下调用它来运行。到目前为止,我已经完成了所有的工作,但是我很难找到解决这个问题的方法。谷歌搜索让我找到了,如果没有安装pandas,这个错误应该会出现,所以我安装了它,并在我的代码中添加了
import pandas
,但我仍然收到了相同的错误

这是我的全部代码:

from google.cloud import bigquery
import os 
import pandas

#need to set credential path
credential_path = (r"C:\Users\crlas\learningPython\google_application_credentials.json")
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credential_path

#create a "Client" object
client = bigquery.Client()

#construct a reference to the "hacker_news" dataset
dataset_ref = client.dataset("hacker_news", project="bigquery-public-data")
#API request - fetch the dataset 
dataset = client.get_dataset(dataset_ref)

#list all tables in the dataset
tables = list(client.list_tables(dataset))
#print all table names
for table in tables:
    print(table.table_id)
print()

#construct a reference to the "full" table
table_ref = dataset_ref.table("full")
#API request - fetch the dataset 
table = client.get_table(table_ref)
#print info on all the columns in the "full" table
print(table.schema)
# print("table schema should have printed above")
print()
#preview first 5 lines of the table
client.list_rows(table, max_results=5).to_dataframe()

正如警告消息所说-UserWarning:如果设置了max_results,则无法使用bqstorage_client,恢复为使用tabledata.list端点获取数据

所以这仍然在使用警告和TableDataAPI来检索数据。 您只需将输出指向dataframe对象并打印它,如下所示:

df = client.list_rows(table, max_results=5).to_dataframe()
print(df)

这很有效,谢谢你!作为一个新手,我不明白你是如何在警告信息中得到答案的。你能解释一下帮我学习吗?