Write a Python function that reads a CSV file and calculates the average value of a specified column. The function should handle potential errors gracefully, such as missing files or invalid data types in the specified column.
file_path (string): The path to the CSV file.column_name (string): The name of the column to calculate the average from.None.Example 1:
file_path = 'data.csv'
column_name = 'age'
average_age = calculate_average(file_path, column_name)
Expected Output: 25.5
Example 2:
file_path = 'data.csv'
column_name = 'salary'
average_salary = calculate_average(file_path, column_name)
Expected Output: None (if all entries are invalid or missing)
file_path = 'data.csv', column_name = 'age'Output25.5WhyThe average of valid age entries in the specified column.file_path = 'data.csv', column_name = 'salary'OutputNoneWhyIf all entries in the salary column are invalid or missing.The CSV file will have at least one header row.The specified column may contain non-numeric values or be empty.def calculate_average(file_path, column_name):