0

I'm trying to create an Excel file that contains 2 columns [Publisher and Frequency] but only the frequency data is in my Excel file

doaj_2015 = pd.read_csv('doaj_20151015_1800_utf8.csv')
publishers = doaj_2015['Publisher'].value_counts()
DataFrame(publishers, columns=['Frequency'])
publishers.to_excel('publisher.xlsx', 
                 sheet_name = 'publisher frequencies', 
                 index = False)

Expected Results

enter image description here

Papouche Guinslyzinho
  • 4,877
  • 9
  • 49
  • 91

2 Answers2

2

publishers is a series. You can reset the index, assign the result to a dataframe, rename the columns, and then export to excel (specifying no index).

df = publishers.reset_index()
df.columns = ['Publisher', 'Frequency']
df.to_excel('publisher.xlsx', 
            sheet_name='publisher frequencies', 
            index=False)
Alexander
  • 96,739
  • 27
  • 183
  • 184
1

See this question on renaming columns.

Once you do the value counts, and coerce as a frame your index becomes the item you are counting. Reset it by:

publishers.reset_index()

and then, you should rename your columns like this:

publishers.columns = ['Publisher', 'Frequency']
Community
  • 1
  • 1
leroyJr
  • 1,080
  • 9
  • 17