0

I have a dataframe called OutputDf that looks like:

            Date  Last Price           Type
1928  02/07/2010        0.00  missing value
1952  31/05/2010         NaN  missing value
1972  03/05/2010         NaN  missing value
2048  13/01/2010        0.00  missing value
659   10/06/2015      402.70        outlier
1020  13/01/2014      471.15        outlier
1309  23/11/2012      492.14        outlier
1698  26/05/2011      404.99        outlier
2057  30/12/2009      476.86        outlier

I am sorting the dataframe by the Date field using:

OutputDf = OutputDf.ix[pd.to_datetime(OutputDf.Date).order().index]

However I am getting future warning:

FutureWarning: order is deprecated, use sort_values(...)

I have tried to change to using sort_values() as suggested by implementing:

OutputDf = OutputDf.sort_values("Date", ascending = True, 
                 inplace = True) 

but I get None returned.

The desired output will be sorted by date (ascending) and would look like:

              Date  Last Price            Type
2057    30/12/2009      476.86         outlier
2048    13/01/2010           0  missing values
1972    03/05/2010         NaN  missing values
1952    31/05/2010         NaN  missing values
1928    02/07/2010           0  missing values
1698    26/05/2011      404.99         outlier
1309    23/11/2012      492.14         outlier
1020    13/01/2014      471.15         outlier
659     10/06/2015       402.7         outlier

How can I implement sort_values correctly?

1
  • 1
    Well, yeah, you used inplace=True and did a reassignment back to the same name. Pick one, but don't use both Commented Nov 26, 2019 at 20:07

1 Answer 1

1

Your problem is here:

OutputDf = OutputDf.sort_values("Date", ascending = True, 
             inplace = True) 

When you're setting the parameter inplace=True, it's making the changes on the actual object that's calling the function, and it returns None.

So basically what you're doing is, you're sorting your dataframe, and then initializing the return value of None back to itself.

You can fix this by removing inplace=True

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.