<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_avro(file_path_or_buffer, df, schema=None, codec='null', append=False):
 """ Avro file writer. Args: file_path_or_buffer: Output file path or file-like object. df: pd.DataFrame. schema: Dict of Avro schema. If it's set None, inferring schema. append: Boolean to control if will append to existing file codec: A string indicating the compression codec to use. Default is no compression ("null"), other acceptable values are "snappy" and "deflate". You must have python-snappy installed to use the snappy codec. """

    if schema is None:
        schema = __schema_infer(df)

    open_mode = 'wb' if not append else 'a+b'

    if isinstance(file_path_or_buffer, six.string_types):
        with open(file_path_or_buffer, open_mode) as f:
            fastavro.writer(f, schema=schema,
                            records=df.to_dict('records'), codec=codec)
    else:
        fastavro.writer(file_path_or_buffer, schema=schema,
                        records=df.to_dict('records'), codec=codec)