为什么我的DataFrame将添加的内容复制到特定列?

时间:2019-04-10 18:25:46

标签: python pandas refinitiv-eikon-api

我试图在for循环中向DataFrame顺序添加新数据。它成功地写入了我(我认为)所选的DataFrame列,但也将数据写入了我不想编辑的另一列。为什么这样做呢?我该如何解决?

# Resetting the data
supplier_rics = supplier_sheet['RICs']
supplier_rics = supplier_rics.dropna()

# Create a DataFrame object that will contain our headlines
supplier_headlines = pd.DataFrame(data={'RIC':supplier_rics},columns=['RIC','Headline'])
supplier_headlines

for i, ric in supplier_rics.iteritems():
    # Add R: prefix to RICS for news search
    supplier_rics[i] = "R:"+supplier_rics[i]

    # Create the news query
    query = supplier_rics[i] + ' AND (Topic:SIG AND Language:LEN)'

    # Make the Eikon API Call 
    headline = ek.get_news_headlines(query=query,count=1)
    headline_string = headline['text'].to_string(index=False)
    # Add the headline text to the supplier_headlines DataFrame Object
    supplier_headlines.iloc[[i,2]] = headline_string

The original DataFrame The DataFrame after it has been looped through

0 个答案:

没有答案