9

I am trying to restructure the way my precipitations' data is being organized in an excel file. To do this, I've written the following code:

import pandas as pd

df = pd.read_excel('El Jem_Souassi.xlsx', sheetname=None, header=None)
data=df["El Jem"]

T=[]
for column in range(1,56):
    liste=data[column].tolist()
    for row in range(1,len(liste)):
        liste[row]=str(liste[row])
        if liste[row]!='nan':
            T.append(liste[row])

result=pd.DataFrame(T)
result

This code works fine and through Jupyter I can see that the result is good screenshot

However, I am facing a problem when attempting to save this dataframe to a csv file.

 result.to_csv("output.csv")

The resulting file contains the vertical index column and it seems I am unable to call for a specific cell.

(Hopefully, someone can help me with this problem) Many thanks !!

1 Answer 1

25

It's all in the docs.

You are interested in skipping the index column, so do:

result.to_csv("output.csv", index=False)

If you also want to skip the header add:

result.to_csv("output.csv", index=False, header=False)


I don't know how your input data looks like (it is a good idea to make it available in your question). But note that currently you can obtain the same results just by doing:

import pandas as pd
df = pd.DataFrame([0]*16)
df.to_csv('results.csv', index=False, header=False)
Sign up to request clarification or add additional context in comments.

5 Comments

I am still new (so I can't upvote ur answer) but thanks a lot for the help. That solved my problem.
@farhat sure! You can accept the answer by clicking the green checkmark near the answer, I'd be obliged :) NB: there might be a much easier way of doing what you want to your data, but it'd be easier to help if you show as how they look like (preferably not through a screenshot).
Thanks again ^^ (for both the advice and the tip about the green checkmark)
@jjj If it gets converted to csv, where does this file save? Thanks in advance!
@jsl5703 what do you mean? You can specify a path yourself. If you won't it'll be in the dir you started python in

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.