Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas dt.weekday to string

" new numpy versions ":

df['weekday'] = df['datetime'].dt.day_name
print df
             datetime  season  holiday  workingday  weather   temp   atemp  
0 2011-01-01 00:00:00       1        0           0        1   9.84  14.395   
1 2011-01-01 01:00:00       1        0           0        1   9.02  13.635   
2 2011-01-01 02:00:00       1        0           0        1   9.02  13.635   
3 2011-01-01 03:00:00       1        0           0        1   9.84  14.395   
4 2011-01-01 04:00:00       1        0           0        1   9.84  14.395   
5 2011-01-01 05:00:00       1        0           0        2   9.84  12.880   
6 2011-01-01 06:00:00       1        0           0        1   9.02  13.635   
7 2011-01-01 07:00:00       1        0           0        1   8.20  12.880   
8 2011-01-01 08:00:00       1        0           0        1   9.84  14.395   
9 2011-01-01 09:00:00       1        0           0        1  13.12  17.425   

   humidity  windspeed  count   weekday  
0        81     0.0000     16  Saturday  
1        80     0.0000     40  Saturday  
2        80     0.0000     32  Saturday  
3        75     0.0000     13  Saturday  
4        75     0.0000      1  Saturday  
5        75     6.0032      1  Saturday  
6        80     0.0000      2  Saturday  
7        86     0.0000      3  Saturday  
8        75     0.0000      8  Saturday  
9        76     0.0000     14  Saturday
Comment

pandas dt.weekday to string

" old nympy versions "
test_date.dt.day_name()

0    Saturday
1    Saturday
2    Saturday
3    Saturday
4    Saturday
5    Saturday
6    Saturday
7    Saturday
8    Saturday
9    Saturday
Name: datetime, dtype: object
Comment

pandas dt.weekday to string

"alternative method":

In [105]:

df['weekday'] = df[['datetime']].apply(lambda x: dt.datetime.strftime(x['datetime'], '%A'), axis=1)
df
Out[105]:
             datetime  season  holiday  workingday  weather   temp   atemp  
0 2011-01-01 00:00:00       1        0           0        1   9.84  14.395   
1 2011-01-01 01:00:00       1        0           0        1   9.02  13.635   
2 2011-01-01 02:00:00       1        0           0        1   9.02  13.635   
3 2011-01-01 03:00:00       1        0           0        1   9.84  14.395   
4 2011-01-01 04:00:00       1        0           0        1   9.84  14.395   
5 2011-01-01 05:00:00       1        0           0        2   9.84  12.880   
6 2011-01-01 06:00:00       1        0           0        1   9.02  13.635   
7 2011-01-01 07:00:00       1        0           0        1   8.20  12.880   
8 2011-01-01 08:00:00       1        0           0        1   9.84  14.395   
9 2011-01-01 09:00:00       1        0           0        1  13.12  17.425   

   humidity  windspeed  count   weekday  
0        81     0.0000     16  Saturday  
1        80     0.0000     40  Saturday  
2        80     0.0000     32  Saturday  
3        75     0.0000     13  Saturday  
4        75     0.0000      1  Saturday  
5        75     6.0032      1  Saturday  
6        80     0.0000      2  Saturday  
7        86     0.0000      3  Saturday  
8        75     0.0000      8  Saturday  
9        76     0.0000     14  Saturday
Comment

PREVIOUS NEXT
Code Example
Python :: pass dictionary to random forest regressor 
Python :: model compile keras 
Python :: __truediv__ 
Python :: __ne__ 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
Python :: NumPy rot90 Example Rotating Twice 
Python :: python service linux 
Python :: how to split a string every 2 characters python 
Python :: saving specific column with pd 
Python :: NumPy unpackbits Code Unpacked array along axis 0 
Python :: drop column 0 to many 
Python :: numpy image processing 
Python :: how to take input as an integer in python 
Python :: first index of an integer less than a value 
Python :: Double all numbers using a map() Function 
Python :: knn compute_distances_two_loop 
Python :: pygame getting your charecter to jump 
Python :: python simplenamespace to json 
Python :: kaggle set utility script 
Python :: how do i add two matrix and store it in a list in python 
Python :: sklearn encoding pipelin 
Python :: jupyter lab move tabs 
Python :: python go back one using abspath 
Python :: ring Reverse List Item 
Python :: ring Using the Natural Library 
Python :: how to get only the string of the input not the spaces arournd it in python 
Python :: python you can think pad baldi 
Python :: pandas to sql arabic 
Python :: placeholder in model form 
Python :: object creation using class constructor 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =