csvtotable
csvtotable copied to clipboard
Added support for excel
Hello @vividvilla ,Your project is perfect!,but,I think added support excel maybe better.
so, I use pandas
and numpy
to read file,As you can see.
def read_file(input_file_name):
import pandas as pd
import numpy as np
suffix = os.path.splitext(input_file_name)[1]
if not suffix:
if six.PY2:
suffix = raw_input('please enter file type.(csv、excel):\t')
else:
suffix = input('please enter file type.(csv、excel):\t')
if 'csv' in suffix:
df = pd.read_csv(input_file_name)
else:
df = pd.read_excel(input_file_name)
headers = [i for i in df.columns]
rows = np.array(df).tolist()
if not headers and len(rows) > 0:
end = len(headers) + 1
headers = ["Column {}".format(n) for n in range(1, end)]
return headers, rows
what are you think?
an excel variant exists already: https://github.com/pyexcel/excel2table.
excel2table 2.3.0 is out.