0

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.

James
  • 1

1 Answers1

1

Bed files are following a fixed width format, so to_csv wouldn'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 tablulate to export as fixed width (see this answer for more details)

mozway
  • 194,879
  • 13
  • 39
  • 75