def write_file(file_path, sep=",", index=True):
    """
    Write DplyFrame to file.
    Write the DplyFrame to the following file types depending on the file path given:
    .csv, .xlsx, .json and .pkl

    :param file_path: the path of the file with proper suffix
    :param sep: the separator for csv files. Default to be comma
    :param index: Write the row name by the index of the DplyFrame. Default to be true
    :return: a function that returns the original DplyFrame
    """

    def to_csv(d1):
        d1.pandas_df.to_csv(file_path, sep=sep, index=index)
        return d1

    def to_excel(d1):
        d1.pandas_df.to_excel(file_path, index=index)
        return d1

    def to_json(d1):
        d1.pandas_df.to_json(file_path)
        return d1

    def to_pickle(d1):
        d1.pandas_df.to_pickle(file_path)
        return d1

    if file_path.endswith(".csv"):
        return to_csv
    if file_path.endswith(".xlsx"):
        return to_excel
    if file_path.endswith(".json"):
        return to_json
    if file_path.endswith(".pkl"):
        return to_pickle
    raise IOError("The file format is not supported.")