Brad Johansen
Brad Johansen

Reputation: 333

Why is my DataFrame duplicating additions to a specific column?

I am trying to sequentially add new data to a DataFrame within a for loop. It successfully writes to the DataFrame column I (I think) selected, but it also writes the data to another column I am not trying to edit. Why is it doing this? How can I fix it?

# 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

Upvotes: 0

Views: 60

Answers (0)

Related Questions