аватар question@mail.ru · 01.01.1970 03:00

How to streamline the dates on the graph in an increase in the order?

Est CSV File with a number of sick people over the past year, but it has an incorrect structure, i.e. At first there is today's date, then yesterday, etc.

how to build the correct schedule, so that from the past to the present, and not vice versa?

   import  PANDAS  as  pd  import  matplotlib.pyplot  as  plandata = pd.read_csv ( 'Data.txt' ) plt.plot (Data [ '"call" ]) plt.show ()     

tried: data = Data [::-1]

аватар answer@mail.ru · 01.01.1970 03:00

If a column with dates has a data type DATETIME64 , then PANDAS will take care of sorting the values ​​along the axis X .

 Class = "" Data-Highlighted = ""> in [ 105 ]: df = pd.dataframe ({ "" dt "" : pd.date_range ( '' 2021-01-01 ', periods =  20 ), : np.random.randint ( 100 , size = )}). sample (frac =  1 ) in [ 106 ]: dfout [ 106 ]:  dt val  15   2021  -01-  16   71    2   2021  -01-03  23    11   2021  -01-  12   29    3   2021  -01-04  66    0   2021  -01-01  52    9   2021  -01-  10   78    18   2021  -01-  19   5    12   2021  -01-  13   64    8   2021  -01-09  81    6   2021  -01-07  73    13   2021  -01-  14   85    10   2021  -01-  11   85    7   2021  -01-08  74    1   2021  -01-02  49    4   2021  -01-05  80    14   2021  -01-  15   38    19   2021  -01-  20   98    5   2021  -01-06  25    17   2021  -01-  18   3    16   2021  -01-  17   69      

We draw with the means of Pandas:

  in [ 108 ]: DF.Set_index () [ "" "" "" "]. Plot () out [ 108 ]: & lt; Axessubplot: xLabel =  'dt'  & gt;     

Latest

Similar