-1

Consider the below data in Excel (.xlsx) format as Input file.Assume the location is C:\Conversion\input.xlsx

enter image description here

The output file should be in the below pipe limited format as text file. the output should be in the below locations C:\Conversion\output\pip.txt

enter image description here

Please help by providing a Python/pandas script for the above output. Note: I am a new learner.

  • The output txt file should not contain any junk and bad character.
  • if the value is blank any cell (input file), it need to store as null value.

Thanks in advance

3

2 Answers 2

0

I'm assuming you don't want index in your output but you want header.

df = pd.read_excel('test.xlsx')
df.to_csv('test.txt', sep='|', index=False)

It will produce a file like that:

col1|col2|col3|col4|col5
a|1|2.0|s|g
s|2|3.0|f|d
d|3||d|s
f|45|4.0|s|

If the header should not be present in the file, you have to adjust that call according to what does the documentation says: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks , My input file as per my question is Excel file and i need the output as Pipe limited as Text file output which i mentioned in the question. I have edited my questions
0

I may be wrong, but this is found in your computer settings. By default your computer is comma delimited. Go to the control panel and find additional settings. There you can change the list separator from commas to pipes.

1 Comment

Thanks sublimizeD, I have tried doing it. I am getting more issue as bad character during the load to database.moreover i have bulk operations which i am trying to achieve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.