0

I created a small dataframe in pandas that looks like this:

df = pd.DataFrame({'weather':[16,22,32,8,2]})
df

in the output is gives me a table:

    weather
0   16
1   22
2   32
3   8
4   2

I cant find a proper explanation on how to change this table so that instead of 0,1,2,3,4 I can input words(for example: Monday, Tuesday etc)

BENY
  • 317,841
  • 20
  • 164
  • 234
Tom
  • 21
  • 5
  • The first column represents the indexes of your rows. You have to add a new column with words (Monday, Thuesday,etc...) – Maxouille Mar 12 '19 at 13:41

2 Answers2

1

This is so called index

df = pd.DataFrame({'weather':[16,22,32,8,2]},index=['Mon','Tue','Wed','Thu','Fri'])
df
Out[36]: 
     weather
Mon       16
Tue       22
Wed       32
Thu        8
Fri        2
BENY
  • 317,841
  • 20
  • 164
  • 234
0

IIUC, if your index are not in order and you want to map them according to the count, you can do:

import calendar
d = {i:e for i,e in enumerate(list(calendar.day_name))}

df.index=df.index.map(d)
print(df)

           weather
Monday          16
Tuesday         22
Wednesday       32
Thursday         8
Friday           2
anky
  • 74,114
  • 11
  • 41
  • 70