Tudee92
Tudee92

Reputation: 27

How to name the rows and columns in dataframe before exporting to excel?

import pandas as pd
df1 = pd.DataFrame(Numpy_Array1)
df2 = pd.DataFrame(Numpy_Array2)
writer = pd.ExcelWriter('Results.xlsx', engine='xlsxwriter')
df1.to_excel(writer, sheet_name = 'Array1')
df2.to_excel(writer, sheet_name = 'Array2')
writer.save()

I am trying to export numpy arrays to excel first converting it to dataframes. Each array has 10 rows and 35 columns, what is the best possible way to name each columns and rows ?

Upvotes: 1

Views: 82

Answers (1)

vi_me
vi_me

Reputation: 408

To name columns in dataframe you can use

df.columns = ['a', 'b']

Upvotes: 1

Related Questions