Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.9 kB
1
Indexable
Never
from cassandra.cluster import Cluster
import pandas as pd
from cassandra.auth import PlainTextAuthProvider


auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra@123')
cluster = Cluster(['172.16.177.58'], auth_provider=auth_provider)
session = cluster.connect('hobs_ods_staging')
cassandra_query = "SELECT * FROM hos_event_recon_summary limit 10"
result_set = session.execute(cassandra_query)
df = pd.DataFrame(result_set, columns=['recon_start_date', 'recon_end_date', 'event_type', 'no_of_failed_events',
                                       'no_of_failed_events_pubished_to_kafka', 'no_of_passed_events',
                                       'no_of_passed_events_via_recon', 'total_no_of_events'])

df['recon_start_date'] = pd.to_datetime(df['recon_start_date']).dt.date
result_df = df.groupby(['recon_start_date', 'event_type']).agg({
    'total_no_of_events': 'sum',
    'no_of_passed_events': 'sum',
    'no_of_failed_events': 'sum',
    'no_of_passed_events_via_recon': 'sum'
}).reset_index()
print(result_df)

above code is printing is below like
  from cassandra.cluster import Cluster
  recon_start_date                event_type  total_no_of_events  no_of_passed_events  no_of_failed_events  no_of_passed_events_via_recon
0       2023-04-05                addAccount                   2                    2                    0                              0
1       2023-05-08          updateSalesOrder                 120                  120                    0                              0
2       2023-05-13                addAccount                   3                    3                    0                              0
3       2023-05-13                addContact                   7                    7                    0                              0
4       2023-05-13               addCustomer                   4                    4                    0                              0
5       2023-05-13             addIndividual                  28                   28                    0                              0
6       2023-05-13           updatePartyRole                  14                   14                    0                              0
7       2023-05-13  updatePartyRoleByAssocId                  14                    0                   14                              0
8       2023-05-13          updateSalesOrder                 120                  120                    0                              0
9       2023-05-17          updateSalesOrder                 120                  120                    0                              0
[13:36:05:hobapp@tcs-hob-sir-env01 ] /app/server/HOBS-DataPipeline_new/modules/devops/dags>

now instead of printing can you send that in mail by using smtp i want those in boxes neatly
Leave a Comment