I used pandas.to_csv() to convert a pandas dataframe to a BED file by doing this:
pd.to_csv('xxx.bed', index=False, sep='\t', header=None)
I want to know if this can successfully convert a dataframe to a bed file, or I am just exporting the dataframe as a csv file.
Bed files are following a fixed width format, so
to_csvwouldn't be useful directly.You have two options:
1- convert your columns to strings with padding to a fixed width, then export to csv
2- use
tablulateto export as fixed width (see this answer for more details)