GonVas / tickerrain

Website that displays in real time tickers being processed by different sources.
MIT License
178 stars 56 forks source link

Error running process.py #5

Open granthoff1107 opened 3 years ago

granthoff1107 commented 3 years ago

Process.py throws an error when running calculate_df

def calculate_df(df):
    data_df = df.filter(['tickers', 'score', 'sentiment'])

    tickers_processed = pd.DataFrame(df.tickers.explode().value_counts())

    tickers_processed = tickers_processed.rename(columns = {'tickers':'counts'})

    tickers_processed['score'] = 0.0
    tickers_processed['sentiment'] = 0.0

     for idx, row_tick in enumerate(tickers_processed.iloc):

at line:

for idx, row_tick in enumerate(tickers_processed.iloc):

Exception has occurred: NotImplementedError ix is not iterable File "C:\Users\MyUser\Desktop\NLP\trading-bot-base\tickerrain\process.py", line 113, in calculate_df for idx, row_tick in enumerate(tickers_processed.iloc): File "C:\Users\MyUser\Desktop\NLP\trading-bot-base\tickerrain\process.py", line 152, in processed_df return calculate_df(df), calculate_df(df_3), calculate_df(df_1) File "C:\Users\MyUser\Desktop\NLP\trading-bot-base\tickerrain\process.py", line 157, in processing_last last_processed, last_processed_3, last_processed_1 = processed_df() File "C:\Users\MyUser\Desktop\NLP\trading-bot-base\tickerrain\process.py", line 169, in asyncio.run(processing_last())

granthoff1107 commented 3 years ago

Not sure if this is related to my package versions or python version but I fixed this issue by using the following code instead:

for idx, row_tick in enumerate(tickers_processed.itertuples(), 1):
    upd_row_sent = row_tick.sentiment
    upd_row_score = row_tick.score
    for row_data in data_df.itertuples():
        if(row_tick.Index in row_data.tickers):
            upd_row_sent += row_data.sentiment['compound'] / row_tick.counts
            upd_row_score += int(row_data.score) / row_tick.counts
            tickers_processed.set_value(row_tick.Index, 'sentiment', upd_row_sent)
            tickers_processed.set_value(row_tick.Index, 'score', upd_row_score)
GonVas commented 3 years ago

I am redoing all of the process, to be faster, the new version will be better.