Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Scheduling and Automating Business Workflows | Automating Business Analysis Tasks
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Business Analysts

bookScheduling and Automating Business Workflows

Workflow automation is a powerful way to streamline business analysis tasks by reducing the need for manual intervention. By running scripts on a schedule, you can ensure that data is processed, analyzed, and reported consistently and on time. Chaining tasks together allows you to create end-to-end processes where the output of one step becomes the input for the next, eliminating repetitive manual steps and minimizing errors. This approach is especially useful for recurring tasks such as daily sales reporting, monthly performance summaries, or regular data cleaning operations.

123456789101112131415161718192021222324252627282930313233343536373839404142
import pandas as pd def clean_data(df): # Remove rows with missing 'Sales' values df = df.dropna(subset=['Sales']) # Convert 'Sales' to numeric df['Sales'] = pd.to_numeric(df['Sales'], errors='coerce') return df def summarize_data(df): # Calculate total and average sales total_sales = df['Sales'].sum() average_sales = df['Sales'].mean() summary = { 'Total Sales': total_sales, 'Average Sales': average_sales } return summary def generate_report(summary, region): # Create a simple text report report = ( f"Sales Report for {region}\n" f"----------------------\n" f"Total Sales: {summary['Total Sales']:.2f}\n" f"Average Sales: {summary['Average Sales']:.2f}\n" ) print(report) def workflow(data, region): cleaned = clean_data(data) summary = summarize_data(cleaned) generate_report(summary, region) # Example usage with sample data for a region data = pd.DataFrame({ 'Product': ['A', 'B', 'C', 'D'], 'Sales': ['100', '200', None, '150'] }) workflow(data, 'North Region')
copy

By breaking down your workflow into modular functions, you make each step reusable and easy to test. These functions can be mixed and matched for different scenarios, making it simple to adapt your automation as business needs change. For instance, the same data cleaning and summarization functions can be reused across different datasets or reporting periods, allowing you to build robust, end-to-end automation pipelines.

123456789101112131415161718192021222324252627282930313233343536
import pandas as pd regions = { 'North': pd.DataFrame({'Product': ['A', 'B'], 'Sales': ['120', '130']}), 'South': pd.DataFrame({'Product': ['C', 'D'], 'Sales': ['110', '140']}), 'East': pd.DataFrame({'Product': ['E', 'F'], 'Sales': ['115', '125']}) } def clean_data(df): df = df.dropna(subset=['Sales']) df['Sales'] = pd.to_numeric(df['Sales'], errors='coerce') return df def summarize_data(df): total_sales = df['Sales'].sum() average_sales = df['Sales'].mean() return {'Total Sales': total_sales, 'Average Sales': average_sales} def generate_report(summary, region): report = ( f"Sales Report for {region}\n" f"----------------------\n" f"Total Sales: {summary['Total Sales']:.2f}\n" f"Average Sales: {summary['Average Sales']:.2f}\n" ) print(report) def workflow(data, region): cleaned = clean_data(data) summary = summarize_data(cleaned) generate_report(summary, region) # Run the workflow for each region for region, data in regions.items(): workflow(data, region)
copy

1. What is the benefit of chaining multiple analysis steps into a single workflow?

2. How does modular code support business process automation?

3. Fill in the blanks: To automate a workflow, define ____ functions and call them in ____ order.

question mark

What is the benefit of chaining multiple analysis steps into a single workflow?

Select the correct answer

question mark

How does modular code support business process automation?

Select the correct answer

question-icon

Fill in the blanks: To automate a workflow, define ____ functions and call them in ____ order.

To automate a workflow, define modular functions and call them in a specific order.
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookScheduling and Automating Business Workflows

Deslize para mostrar o menu

Workflow automation is a powerful way to streamline business analysis tasks by reducing the need for manual intervention. By running scripts on a schedule, you can ensure that data is processed, analyzed, and reported consistently and on time. Chaining tasks together allows you to create end-to-end processes where the output of one step becomes the input for the next, eliminating repetitive manual steps and minimizing errors. This approach is especially useful for recurring tasks such as daily sales reporting, monthly performance summaries, or regular data cleaning operations.

123456789101112131415161718192021222324252627282930313233343536373839404142
import pandas as pd def clean_data(df): # Remove rows with missing 'Sales' values df = df.dropna(subset=['Sales']) # Convert 'Sales' to numeric df['Sales'] = pd.to_numeric(df['Sales'], errors='coerce') return df def summarize_data(df): # Calculate total and average sales total_sales = df['Sales'].sum() average_sales = df['Sales'].mean() summary = { 'Total Sales': total_sales, 'Average Sales': average_sales } return summary def generate_report(summary, region): # Create a simple text report report = ( f"Sales Report for {region}\n" f"----------------------\n" f"Total Sales: {summary['Total Sales']:.2f}\n" f"Average Sales: {summary['Average Sales']:.2f}\n" ) print(report) def workflow(data, region): cleaned = clean_data(data) summary = summarize_data(cleaned) generate_report(summary, region) # Example usage with sample data for a region data = pd.DataFrame({ 'Product': ['A', 'B', 'C', 'D'], 'Sales': ['100', '200', None, '150'] }) workflow(data, 'North Region')
copy

By breaking down your workflow into modular functions, you make each step reusable and easy to test. These functions can be mixed and matched for different scenarios, making it simple to adapt your automation as business needs change. For instance, the same data cleaning and summarization functions can be reused across different datasets or reporting periods, allowing you to build robust, end-to-end automation pipelines.

123456789101112131415161718192021222324252627282930313233343536
import pandas as pd regions = { 'North': pd.DataFrame({'Product': ['A', 'B'], 'Sales': ['120', '130']}), 'South': pd.DataFrame({'Product': ['C', 'D'], 'Sales': ['110', '140']}), 'East': pd.DataFrame({'Product': ['E', 'F'], 'Sales': ['115', '125']}) } def clean_data(df): df = df.dropna(subset=['Sales']) df['Sales'] = pd.to_numeric(df['Sales'], errors='coerce') return df def summarize_data(df): total_sales = df['Sales'].sum() average_sales = df['Sales'].mean() return {'Total Sales': total_sales, 'Average Sales': average_sales} def generate_report(summary, region): report = ( f"Sales Report for {region}\n" f"----------------------\n" f"Total Sales: {summary['Total Sales']:.2f}\n" f"Average Sales: {summary['Average Sales']:.2f}\n" ) print(report) def workflow(data, region): cleaned = clean_data(data) summary = summarize_data(cleaned) generate_report(summary, region) # Run the workflow for each region for region, data in regions.items(): workflow(data, region)
copy

1. What is the benefit of chaining multiple analysis steps into a single workflow?

2. How does modular code support business process automation?

3. Fill in the blanks: To automate a workflow, define ____ functions and call them in ____ order.

question mark

What is the benefit of chaining multiple analysis steps into a single workflow?

Select the correct answer

question mark

How does modular code support business process automation?

Select the correct answer

question-icon

Fill in the blanks: To automate a workflow, define ____ functions and call them in ____ order.

To automate a workflow, define modular functions and call them in a specific order.
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 6
some-alt