I am trying to sort the data listed below by date using df.sort_values(by='date') , however this will not work. Any ideas how I can do this to make sure it is sorted correctly?
df.sort_values(by='date')
symbol date open close high low 0 GOOG 2007-01-03 232.77 233.56 238.09 230.32 1 GOOG 2007-01-05 241.01 243.35 243.51 238.82 2 GOOG 2007-01-04 234.27 241.39 241.73 233.94 ... 2692 GOOG 2017-11-30 1022.37 1021.41 1028.49 1015.00 2693 GOOG 2017-11-29 1042.68 1021.66 1044.08 1015.65 2694 GOOG 2017-12-01 1015.80 1010.17 1022.49 1002.02
df.sort_values() returns a sorted DF, but it is not sorted.
df.sort_values()
So either use:
df = df.sort_values(by='date')
or
df.sort_values(by='date', inplace=True)
Try
df['Date']=pd.to_datetime(df.Date) df.sort_values(['Date'])
If you have a dataframe as below:
df = pd.DataFrame({'col1' : ['A', 'A', 'B', np.nan, 'D', 'C'], 'col2' : [2, 1, 9, 8, 7, 4], 'col3': [0, 1, 9, 4, 2, 3], })
Here's how you sort it:
df = df.sort_values(by=['col1'])
A similar problem with the solution for stackoverflow: how to sort pandas data from a single Panda column link: http://pandas.pydata.org/pandas-docs/version/0.19.2/generated/pandas.DataFrame.sort.html
Source: https://habr.com/ru/post/1274417/More articles:javascript encryption? - javascriptGroupby keep order among groups? Which way? - pythonRegular expression Remove spaces from a group - javaPandas sort by month by index - pythonFirebase optimized query - androidJVM JIT method is recalculated for pure methods - javahow to sort pandas dataframe from one column - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1274420/can-hotspot-optimize-away-redundant-calls-to-pure-methods-without-inlining-them&usg=ALkJrhhiFacUf_KzQvLryVENQ-pmR9eRVgEnable if statement? - javaReverse string order inside brackets in vim - vimAll Articles