D
D
Denis Klimanov2021-09-08 19:18:24
Python
Denis Klimanov, 2021-09-08 19:18:24

Merging exel and csv files using pandas?

Hello Habr family!!!
There is an .xlsx file of such content.
6138e1373dc10132178706.png
There is also a .csv file.
6138e16b0b8c9120613397.png
How can I combine both files into .xlsx format in such a way
6138e1d97860d344660918.png
that the data would be added to subsequent columns with each entry ???
At the same time, the number of lines may differ for each entry!

file_csv = pd.read_csv("temp") # .csv
        file_exel = pd.read_excel(old_filename) # Присутствует Unnamed
        appended_df = pd.concat([file_csv, file_exel], axis=1)
        appended_df.to_excel('result.xlsx', index=False)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-09-09
@stantes

If we are talking about the fact that the first line gets the names "Unnamed ...", then this is because it is trying to determine the names of the columns, but there are none. In this case, the easiest way is to disable headers altogether by adding header=None to all functions (file upload and download)
file_csv = pd.read_csv("temp", header=None)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question