File size: 1,908 Bytes
9321404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import re
import datetime
import plotly.express as px
import datetime

def clean_text(text):
    new_text = text
    for rgx_match in ['[A-Z ]+:']:
        new_text = re.sub(rgx_match, '', new_text)
    return new_text

def prepare_df(df, category):
    try:
        df.drop(columns=['Unnamed: 0'], inplace=True)
    except:
        pass

    if category == 'Crude Oil':
        news_data = df[(df['topic_verification'] == 'Crude Oil') | (df['topic_verification'] == 'Macroeconomic & Geopolitics')]
    if category == 'Light Ends':
        news_data = df[(df['topic_verification'] == 'Light Ends')]
    if category == 'Middle Distillates':
        news_data = df[(df['topic_verification'] == 'Middle Distillates')]
    if category == 'Heavy Distillates':
        news_data = df[(df['topic_verification'] == 'Heavy Distillates')]

    actual_day = datetime.date.today() - datetime.timedelta(days=1)
    pattern_del = actual_day.strftime('%b').upper()

    filter = news_data['headline'].str.contains(pattern_del)
    news_data = news_data[~filter]

    return news_data

def plot_3dgraph(news_data):
    fig = px.scatter_3d(news_data, 
                        x='neutral_score', 
                        y='negative_score', 
                        z='positive_score',
                        color='positive_score', 
                        hover_name ='headline', 
                        color_continuous_scale='RdBu', 
                        size_max=40,
                        size='negative_score',
                        text='headline',
                        hover_data='topic_verification')

    fig.update_layout(
        height=800,
        title=dict(text=f"Platts News Sentiments ({datetime.datetime.now().strftime('%d/%m/%y')})<br><sup>Hover cursor on a datapoint to show news title</sup>", font=dict(size=35), automargin=False)
    )

    fig.update_traces(textfont_size=8)

    return fig