Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format a Date column in a Data Frame

Tags:

I've the following data from a data frame

Name,JoiningDate,AmtPaid Joe,12/31/09,1000 Amy,10/28/09,100 John,05/06/10,200 

The Joining Date is coming in as a factor (when I sapply). How can I convert this to date and then sort on JoiningDate?

like image 519
Jayanth Avatar asked Nov 01 '10 09:11

Jayanth


People also ask

How do I change the format of a column in pandas?

The best way to convert one or more columns of a DataFrame to numeric values is to use pandas. to_numeric() . This function will try to change non-numeric objects (such as strings) into integers or floating-point numbers as appropriate.


1 Answers

This should do it (where df is your dataframe)

df$JoiningDate <- as.Date(df$JoiningDate , format = "%m/%d/%y")  df[order(df$JoiningDate ),] 
like image 109
Tom Liptrot Avatar answered Oct 08 '22 03:10

Tom Liptrot