Please try this:
import pandas as pd
from io import StringIO
# Create DataFrame
df = pd.read_csv(StringIO(data))
# Group by 'StartDate', 'Commodity', 'DealType' and calculate necessary aggregates
agg_df = df.groupby(['StartDate', 'Commodity']).agg(
total_MTMValue=('MTMValue', 'sum'),
total_FixedPriceStrike_times_Quantity=('FixedPrice', lambda x: (x * df.loc[x.index, 'Quantity']).sum()),
total_Quantity=('Quantity', 'sum')
).reset_index()
# Calculate 'FloatPrice'
agg_df['FloatPrice'] = -(agg_df['total_MTMValue'] -
…
Top comments (0)