Giter Club home page Giter Club logo

hello-world's Introduction

Hello-world

Learning Github I am learning about branches and commit import pandas as pd

tax_keywords = ['HST', 'GST', 'QST']

def replace_tax_descriptions(group): # Sort transactions by amount in descending order sorted_group = group.sort_values(by='Amount', ascending=False)

# Filter for non-tax transactions
non_tax_rows = sorted_group[~sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
non_tax_descriptions = non_tax_rows['Description'].tolist()

# Only proceed if there are non-tax descriptions
if non_tax_descriptions:
    # Identify tax rows
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        # Replace tax description with the first available non-tax description and mark as updated
        transactions_df.at[idx, 'Updated Description'] = non_tax_descriptions.pop(0)
        transactions_df.at[idx, 'Update Flag'] = 1
else:
    # If no non-tax descriptions are available, leave as is and do not update
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        transactions_df.at[idx, 'Updated Description'] = transactions_df.at[idx, 'Description']
        transactions_df.at[idx, 'Update Flag'] = 0

Group by Date and Employee Name, then apply the replacement function

grouped = transactions_df.groupby(['Date', 'Employee Name']) grouped.apply(replace_tax_descriptions)

def replace_tax_descriptions(group): print("Processing group:", group) # Debug: print the group being processed sorted_group = group.sort_values(by='Amount', ascending=False) non_tax_rows = sorted_group[~sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)] non_tax_descriptions = non_tax_rows['Description'].tolist()

if non_tax_descriptions:
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        transactions_df.at[idx, 'Updated Description'] = non_tax_descriptions.pop(0)
        transactions_df.at[idx, 'Update Flag'] = 1
else:
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        transactions_df.at[idx, 'Updated Description'] = transactions_df.at[idx, 'Description']
        transactions_df.at[idx, 'Update Flag'] = 0

grouped = transactions_df.groupby(['Date', 'Employee Name']) grouped.apply(replace_tax_descriptions)

..(.??;&@@"""@

import pandas as pd

tax_keywords = ['HST', 'GST', 'QST']

def replace_tax_descriptions(group): # Sort transactions by amount in descending order sorted_group = group.sort_values(by='Amount', ascending=False)

# Filter for non-tax transactions and get their descriptions
non_tax_rows = sorted_group[~sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
non_tax_descriptions = non_tax_rows['Description'].tolist()

# Process each row to replace tax descriptions
tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
for idx, tax_row in tax_rows.iterrows():
    if non_tax_descriptions:
        # Replace tax description with the first available non-tax description and update the flag
        transactions_df.at[idx, 'Updated Description'] = non_tax_descriptions.pop(0)
        transactions_df.at[idx, 'Update Flag'] = 1
    else:
        # If no more non-tax descriptions are available, leave the tax descriptions as is
        transactions_df.at[idx, 'Updated Description'] = transactions_df.at[idx, 'Description']
        transactions_df.at[idx, 'Update Flag'] = 0

Apply the function to each group

grouped = transactions_df.groupby(['Date', 'Employee Name']) grouped.apply(replace_tax_descriptions)

hello-world's People

Contributors

leena-verma avatar

Watchers

 avatar

hello-world's Issues

Code

import pandas as pd

tax_keywords = ['HST', 'GST', 'QST']

def replace_tax_descriptions(group):
# Sort transactions by amount in descending order
sorted_group = group.sort_values(by='Amount', ascending=False)

# Filter for non-tax transactions
non_tax_rows = sorted_group[~sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
non_tax_descriptions = non_tax_rows['Description'].tolist()

# Only proceed if there are non-tax descriptions
if non_tax_descriptions:
    # Identify tax rows
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        # Replace tax description with the first available non-tax description and mark as updated
        transactions_df.at[idx, 'Updated Description'] = non_tax_descriptions.pop(0)
        transactions_df.at[idx, 'Update Flag'] = 1
else:
    # If no non-tax descriptions are available, leave as is and do not update
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        transactions_df.at[idx, 'Updated Description'] = transactions_df.at[idx, 'Description']
        transactions_df.at[idx, 'Update Flag'] = 0

Group by Date and Employee Name, then apply the replacement function

grouped = transactions_df.groupby(['Date', 'Employee Name'])
grouped.apply(replace_tax_descriptions)

-//new

import pandas as pd

tax_keywords = ['HST', 'GST', 'QST']

def replace_tax_descriptions(group):
# Sort transactions by amount in descending order
sorted_group = group.sort_values(by='Amount', ascending=False)

# Filter for non-tax transactions and get their descriptions
non_tax_rows = sorted_group[~sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
non_tax_descriptions = non_tax_rows['Description'].tolist()

# Check if there are non-tax descriptions available
if not non_tax_descriptions:
    # If no non-tax descriptions, leave all descriptions as is and set flag to 0
    sorted_group['Updated Description'] = sorted_group['Description']
    sorted_group['Update Flag'] = 0
else:
    # Process each row to replace tax descriptions
    tax_rows = sorted_group[sorted_group['Description'].str.contains('|'.join(tax_keywords), case=False, na=False)]
    for idx, tax_row in tax_rows.iterrows():
        if non_tax_descriptions:
            # Replace tax description with the first available non-tax description and update the flag
            transactions_df.at[idx, 'Updated Description'] = non_tax_descriptions.pop(0)
            transactions_df.at[idx, 'Update Flag'] = 1
        else:
            # If no more non-tax descriptions are available, leave the tax descriptions as is
            transactions_df

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.