def create_tsv(df, filename=None):
    """Convert pandas DataFrame to text-based table for SISSO.

    Args:
        df (pandas DataFrame): Dataframe of samples and features.
        filename: Path for writing file (optional).

    Returns (if filename==None):
        table (string)
    """
    table = df.to_string()
    lines = table.splitlines()
    index_name = lines.pop(1).strip()
    lines[0] = index_name + lines[0][len(index_name):]
    table = '\n'.join(lines)
    if filename is not None:
        with open(filename, 'w') as f:
            f.write(table)
    else:
        return table