0

I have a CSV file in the following format:

Here there is a header with some text and spaces that I want to ignore

XYZABC-KIU 7458965       45874532NB1Hello James Webb 1         NASA                 458741569          USA
XYZABC-KIU 4587458       45874532NB1Hello James Webb 2         NASA                 458741569          USA
XYZABC-KIU 7458965       45874532NB1Hello James Webb 3         NASA                 458741569          USA

Here there is a footer with some text and spaces that I want to ignore

I want to read this .csv file maybe with the pandas library but I am also open to other useful tools and transform/export it into an excel file looking like this:

Column 1                       Column 2   Column 3
45874532NB1Hello James Webb 1     NASA       USA
45874532NB1Hello James Webb 2     NASA       USA
45874532NB1Hello James Webb 3     NASA       USA

This is the first approach I used:

import pandas as pd

read_file = pd.read_csv('File name.csv')
read_file.to_excel('File name.xlsx', index=None, header=None)

But the generated excel file looks like this:

Column 1
45874532NB1Hello James Webb 1     NASA       USA
45874532NB1Hello James Webb 2     NASA       USA
45874532NB1Hello James Webb 3     NASA       USA

What should I do to obtain the desired excel format?

fsdhre
  • 1

0 Answers0