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
  • If write `DataFrame df`, what is `print (df.info())` ? – jezrael May 18 '19 at 11:55
  • @jezrael 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 – Charisma Bathara May 18 '19 at 12:01

2 Answers2

5

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

pd.ExcelWriter("df2018.xlsx")
df.to_excel(writer, index = False)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
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

Sankar guru
  • 935
  • 1
  • 7
  • 16