In [1]:
import pandas as pd

# Lookup table
lookup_table = pd.DataFrame(
    {
        "Country": ["USA", "USA", "USA", "EU", "GER", "CHN"],
        "Data": [
            "Employment",
            "Factory Orders",
            "Consumer Confidence",
            "Consumer Confidence",
            "Factory Orders",
            "Aggregate Social Finance",
        ],
        "Coming_Up_Next_Week": [1, 1, 0, 1, 1, 0],
        "Importance_for_Workflow": [5, 3, 4, 4, 1, 5],
    }
)

# Example calendar
calendar = pd.DataFrame(
    {
        "Country": ["USA", "EU", "CHN", "USA", "GER", "USA"],
        "Data": [
            "Employment",
            "Consumer Confidence",
            "Aggregate Social Finance",
            "Factory Orders",
            "Factory Orders",
            "Consumer Confidence",
        ],
        "Date": ["May 6th", "May 7th", "May 15th", "May 7th", "May 8th", "May 21st"],
        "Forecast": [3.8, 100, 50, 1.5, 2, 103],
        "Expected": [3.7, 105, 55, 1.6, 2.1, 103],
        "Previous": [3.9, 98, 48, 1.4, 1.9, 106],
    }
)

# Merge and calculate scores
merged = pd.merge(lookup_table, calendar, on=["Country", "Data"], how="left")
merged["Score"] = merged["Coming_Up_Next_Week"] * merged["Importance_for_Workflow"]
merged = merged[merged["Score"] > 0]
sorted_calendar = merged.groupby("Date")[
    ["Country", "Data", "Forecast", "Expected", "Previous"]
].apply(lambda x: x.sort_values(by=["Country", "Data"]))

sorted_calendar
Out[1]:
Country Data Forecast Expected Previous
Date
May 6th 0 USA Employment 3.8 3.7 3.9
May 7th 3 EU Consumer Confidence 100.0 105.0 98.0
1 USA Factory Orders 1.5 1.6 1.4
May 8th 4 GER Factory Orders 2.0 2.1 1.9