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
  • 5,277
  • 14
  • 58
  • 101

2 Answers2

3

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
  • 105,104
  • 32
  • 201
  • 196
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,110
  • 9
  • 17