read the excel file with words and write it to the csv file in Python


I have an excel file with string stored in each cell:

rtypl   srtyn   OCVXZ   srtyn
xcvwh   mvwhd   WQKXM   mvwhd
GYTR    xvnm    YTZN    YTZN
ngws    jklp    PLNM    jklp

I wanted to read excel file and write it in csv file. As you can see below:

import pandas as np
import csv

df = pd.read_excel(file, encoding='utf-16')
words= open("words.csv",'wb')
wr = csv.writer(words, dialect='excel')
for item in df:

But it reads the each line in separated alphabet and not as a string.


I am limited to write file as csv as I gonna use the result in a library that has lots of facility for csv file. Any advice on how I can read all the rows as a string in the cell is appreciated.

You can try the easiest solution:

# -*- coding: utf-8 -*-
import pandas as pd

df = pd.read_excel(file, encoding='utf-16')
df.to_csv('words.csv', encoding='utf-16')