Renaming a series in pandas

I work with a series, and I was wondering how I can rename a series when writing to a file. For example, my csv output consists of the following:

Gene_Name,0 A2ML1,15 AAK1,8 

I want it to be as follows:

 Gene_Name,Count A2ML1,15 AAK1,8 

Note. I do not want my title to be "Gene_Name, 0", but "Gene_Name, Count". How can i do this?

+7
source share
2 answers

To make "Count" the name of your series, simply set it with your_series.name = "Count" and then call to_csv as follows: your_series.to_csv("c:\\output.csv", header=True, index_label="Gene_Name") .

+10
source

Another way to do this:

 s.to_frame("Count").to_csv("output.csv", header=True, index_label="Gene_Name") 

or

 s.reset_index(name="Count").to_csv("output.csv", header=True, index_label="Gene_Name") 
+2
source

All Articles