Python 这个错误是什么意思';索引器错误:索引0超出大小为0';的轴0的界限;?

Python 这个错误是什么意思';索引器错误:索引0超出大小为0';的轴0的界限;?,python,pandas,sqlite,Python,Pandas,Sqlite,我正在学习一个训练聊天机器人的教程。然而,我不断地得到这个错误,我不知道这意味着什么, 第16行,在 last_unix=df.tail(1)['unix'].values[0] 索引器:索引0超出大小为0的轴0的界限 下面是我的代码。第16行是last\u unix=df.tail(1)[unix']值[0] import sqlite3 import pandas as pd timeframes = ['2015-01'] for timeframe in timeframes:

我正在学习一个训练聊天机器人的教程。然而,我不断地得到这个错误,我不知道这意味着什么, 第16行,在 last_unix=df.tail(1)['unix'].values[0] 索引器:索引0超出大小为0的轴0的界限

下面是我的代码。第16行是last\u unix=df.tail(1)[unix']值[0]

import sqlite3
import pandas as pd

timeframes = ['2015-01']

for timeframe in timeframes:
    connection = sqlite3.connect('/Users/danieldossantos/Desktop/Faisnet/RC_{}.db'.format(timeframe))
    c = connection.cursor()
    limit = 5000
    last_unix = 0
    cur_length = limit
    counter = 0
    test_done = False
    while cur_length == limit:
        df = pd.read_sql("SELECT * FROM parent_reply WHERE unix > {} AND parent NOT NULL AND score > 0 ORDER BY unix ASC LIMIT {}".format(last_unix, limit), connection)
        last_unix = df.tail(1)['unix'].values[0]
        cur_length = len(df)
        if not test_done:
            with open("test.from", 'a', encoding='utf8') as f:
                for content in df['parent'].values:
                    f.write(content+'\n')
            with open("test.to", 'a', encoding='utf8') as f:
                for content in df['comment'].values:
                    f.write(content+'\n')
            test_done = True

        else:
            with open("train.from", 'a', encoding='utf8') as f:
                for content in df['parent'].values:
                    f.write(content+'\n')
            with open("train.to", 'a', encoding='utf8') as f:
                for content in df['comment'].values:
                    f.write(content+'\n')

        counter += 1
        if counter % 20 == 0:
            print(counter*limit, 'rows completed so far')
我试着加上

df = pd.read_sql(
            "SELECT * FROM parent_reply WHERE unix > {} AND parent NOT NULL AND parent != 'False' AND score > 0 ORDER BY unix ASC LIMIT {}".format( last_unix, limit), connection)
但那没用


我应该得到已完成的行数。

这仅仅意味着运行此
df.tail(1)[unix']时没有返回数据。值[0]

它给出一个空的numpy数组,因此第一个位置或第0个索引处没有任何内容。
pd.read\u sql
行之后,您可以做的是-

  • print(df.shape)
    查看查询返回的行数和列数
  • print(df.tail(1)['unix'])
    查看数据帧最后一行的
    unix
    列,并检查它是否有任何值

您只需要计数吗?然后您可以直接在查询中写入
count(*)
。检查
print(df.tail(1)['unix'])
可能是因为您在那里没有获得任何数据。看起来您的查询有问题。您能否提供有关您正在尝试执行的操作的更多详细信息,并相应地推荐查询。问题不在熊猫身上。@Abhilash Awasthi我正在学习创建聊天机器人的教程。这是我正在学习的教程。我从torrent链接获得了数据集,我不确定这是否是一个问题。这是该网站,我在执行打印(df.shape)和/或打印(df.tail(1)['unix'])权限错误:[Errno 13]权限被拒绝:'test.from'@DanieldosSantos请将整个错误粘贴到您现在面临的问题中。