Last active
January 3, 2022 09:20
-
-
Save karamanbk/d0477bf8cff17c1732eac13cd4a840c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#converting the type of Invoice Date Field from string to datetime. | |
tx_data['InvoiceDate'] = pd.to_datetime(tx_data['InvoiceDate']) | |
#creating YearMonth field for the ease of reporting and visualization | |
tx_data['InvoiceYearMonth'] = tx_data['InvoiceDate'].map(lambda date: 100*date.year + date.month) | |
#calculate Revenue for each row and create a new dataframe with YearMonth - Revenue columns | |
tx_data['Revenue'] = tx_data['UnitPrice'] * tx_data['Quantity'] | |
tx_revenue = tx_data.groupby(['InvoiceYearMonth'])['Revenue'].sum().reset_index() | |
tx_revenue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment