convert my excel file into dbf file using python

Viewed 49

I would like to convert my excel file into dbf file using python.

sample input file emp.xlsx is as below

enter image description here

I went through the below links and tried.

convert csv file to dbf

Convert .csv file into .dbf using Python?

dbf file is created but all the dbf file contents are MEMO only. I need above data as it is in dbf file also. But all are MEMO only. see the below screenshot of output.dbf

enter image description here

I used below python script

import pandas as pd
import dbf

# convert list into string
def list_to_string(mylist): 
    str1 = "," 
    return (str1.join(mylist))

# read from xls file
data=pd.read_excel('emp.xlsx')

# convert column name list into string
myheader = list_to_string(data.columns)

# write to csv
data.to_csv('test.csv',index=None,header=True)

# convert csv into dbf with header
dbf.from_csv(csvfile='test.csv', filename='output.dbf',field_names=myheader.split(','),  to_disk=True)

test.csv file content open through excel application

id  name       phone       dob
101 Joseph  3883474834  10-12-2020
102 Kaif    5454564644  14-12-2020
103 John    2344553354  17-12-2020

test.csv contents open through notepad

id,name,phone,dob
101,Joseph,3883474834,2020-12-10
102,Kaif,5454564644,2020-12-14
103,John,2344553354,2020-12-17
0 Answers
Related