3

let's say, I exported my file in excel

statement Export

ln[] = writer = pd.ExcelWriter("df2018.xlsx")
writer = pd.ExcelWriter("df2018.xlsx", index = false)
df2018.to_excel(writer)
writer.save()

out[] = 
row0  (blank)  kanwil     jan 2018  feb 2018   janfeb 2018 
row1    0      sunarto    45878     545458     5454878
row2    1      hartanto   123456    545454     4444549
row3    2      pemabuk    9547      787896     4579798

(if data frame is df2018)

my expected :

row0  kanwil     jan 2018  feb 2018   janfeb 2018 
row1  sunarto    45878     545458     5454878
row2  hartanto   123456    545454     4444549
row3  pemabuk    9547      787896     4579798

i wanna delete first column

i've tried

pd.ExcelWriter("df2018.xlsx", index = false)

but it doesn't work

what should i do if i want to delete first column when i exported csv or excel

in a fact, i get info from my data frame (df2018) below:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 154 entries, 2 to 155
Data columns (total 5 columns):
Kanwil                 149 non-null object
Cabang                 137 non-null object
Income Januari 2018    151 non-null object
Income Febuari 2018    151 non-null object
Income Jan-Feb 2018    151 non-null object
dtypes: object(5)
memory usage: 4.2+ KB
None
2
  • If write DataFrame df, what is print (df.info()) ? Commented May 18, 2019 at 11:55
  • @jezrael <class 'pandas.core.frame.DataFrame'> Int64Index: 154 entries, 2 to 155 Data columns (total 5 columns): Kanwil 149 non-null object Cabang 137 non-null object Income Januari 2018 151 non-null object Income Febuari 2018 151 non-null object Income Jan-Feb 2018 151 non-null object dtypes: object(5) memory usage: 4.2+ KB None Commented May 18, 2019 at 12:01

2 Answers 2

5

I believe you need specify parameter index=False in DataFrame.to_excel:

pd.ExcelWriter("df2018.xlsx")
df.to_excel(writer, index = False)
Sign up to request clarification or add additional context in comments.

1 Comment

If you are using multiindex then this won't work.
0

Try to like these Reference pandas Excel writer:

https://pbpython.com/improve-pandas-excel-output.html https://xlsxwriter.readthedocs.io/working_with_pandas.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.