1

I need to remove the dfA index because when I print dfA i have:

      Este Mes  Subastas
0   01/01/2018  39

And I need:

Este Mes  Subastas
01/01/2018  39

How can I do that? Because I know if I read the csv file and I write index=False but the problem is I convert my original csv and in the first time I need the index to operate and have dfA. I can´t give a name to index and del the column after because this is a restriction I will use again the dfA to paste it in a xls but without the index

import pandas as pd

df = pd.read_csv('este_mes.csv', sep=',')
df1 = df.groupby(['Fecha'])['Subastas'].sum()
df2 = df1.to_frame().reset_index()

dfA = df2
dfA.columns = ['Este Mes', 'Subastas']
df2 = df2.Subastas
df2.to_csv('este_mes_subastas2.csv', index=False)

SOLUTION:

I can do it without remove the index because I need to paste the dfA on a xlsx so when I did it I set index=Falseand I had the results I was looking for!

import pandas as pd

df = pd.read_csv('este_mes.csv', sep=',')
df1 = df.groupby(['Fecha'])['Subastas'].sum()
df2 = df1.to_frame().reset_index()

dfA = df2
dfA.columns = ['Este Mes', 'Subastas']
df2 = df2.Subastas
df2.to_csv('este_mes_subastas2.csv', index=False)


writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')

dfA.to_excel(writer, sheet_name='Este Mes x Dia',index=False)

1 Answer 1

1

You want to use the pd.DataFrame.to_string method with an argument of index=False

print(df.to_string(index=False))

Este Mes  Subastas
01/01/2018        39

Note: I'm not a fan of the resulting formatting.

Sign up to request clarification or add additional context in comments.

2 Comments

yes but i don't want to change the dataframe to a string
the other way is add headers to df1but I don´t know how I can do it

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.