Python 连接数据帧

Python 连接数据帧,python,pandas,Python,Pandas,我从Yahoo finance抓取了一些表,并尝试将它们连接到一个数据帧中,但收到一条错误消息: “ValueError:没有要连接的对象” 以下是脚本: CalendarDays = 3 #<-- specify the number of calendar days you want to grab earnings release info for tables = [] #<-- initialize an empty list to store your tables f

我从Yahoo finance抓取了一些表,并尝试将它们连接到一个数据帧中,但收到一条错误消息:

“ValueError:没有要连接的对象”

以下是脚本:

CalendarDays = 3 #<-- specify the number of calendar days you want to grab earnings release info for
tables = [] #<-- initialize an empty list to store your tables

for i in trange(CalendarDays, file = sys.stdout, desc = 'Grabbing companies with earnings releases in the next ' + str(CalendarDays) + ' days'):

    for i in range(CalendarDays): #<-- Grabs earnings release info for the next x days on the calendar
        try: 
            date = (datetime.date.today() + datetime.timedelta(days = i )).isoformat() #get tomorrow in iso format as needed'''
            pd.set_option('display.max_column',None)
            url = pd.read_html("https://finance.yahoo.com/calendar/earnings?day="+date, header=0)
            table = url[0]
            table['Earnings Release Date'] = date
            tables.append(table) #<-- append each table into your list of tables
        except ValueError:
            continue

df = pd.concat(tables, ignore_index = True) #<-- take your list of tables into 1 final dataframe

CalendarDays=3#首先,在我看来,有两个循环似乎在重复相同的任务。
对于交易中的i(日历日…):
对于交易中的i(日历日):

代码中的其余部分都可以正常工作。试着用更长的时间进行测试。并不是每天都公布收入。我已经测试了6天,其中4天有数据。对于没有收入发布的一天,不会返回任何表,您可以使用
try有效地禁用此错误。。。除了:

但是,如果连续3天都没有发布,您的列表将包含空表,脚本将突然结束


如果。。。否则阻塞,因为这可能会频繁发生并优雅地退出脚本

FVIW您的代码对我来说运行良好,没有任何更改(添加了几个导入)。得到了一个(39,7)形状的df。要么你当时上网有问题:-)要么是老熊猫?也许值得检查他们的版本?