I can not build a display on the graph of the 3rd column from the csv file depending on the Date column.

Sample data (with column names) in a CSV file:

 Date,1,2,3,4,A,B 2010-01-04,213.429998,214.499996,212.38000099999996,214.009998,123432400,27.727039 

Date - the first column with dates, a['3'].plot() - display the 3rd column with (it is signed like "3") - does not work.

 import pandas as pd import matplotlib.pyplot as plt a = pd.read_csv('C:/Users/II/Downloads/222.csv', sep=',', encoding='latin1', parse_dates=['Date'], dayfirst=True, index_col='Date') a['3'].plot() 

    2 answers 2

    Here is the visualization option in Pandas:

    Data:

     import pandas as pd import pandas_datareader.data as wb import matplotlib.pyplot as plt a = wb.DataReader('GOOG', 'yahoo', '2017-01-01') # симулируем ваш DF a = a.reset_index() a.columns = ['Date', '1','2','3','4','A','B'] print(a.head()) 

    Conclusion:

      Date 1 2 3 4 AB 0 2017-01-03 778.809998 789.630005 775.799988 786.140015 1643100 786.140015 1 2017-01-04 788.359985 791.340027 783.159973 786.900024 1065400 786.900024 2 2017-01-05 786.080017 794.479980 785.020020 794.020020 1315400 794.020020 3 2017-01-06 795.260010 807.900024 792.203979 806.150024 1620500 806.150024 4 2017-01-09 806.400024 809.966003 802.830017 806.650024 1272400 806.650024 

    Visualization

     import matplotlib matplotlib.style.use('ggplot') a.set_index('Date')['3'].plot() 

    or:

     a.plot(x='Date', y='3') plt.show() 

    The result will be the same:

    enter image description here

      code is working. you must first separate the dates into a separate array and convert a few, then for each column you can build a graph

       import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import datetime as dt dates = ['01/02/2017','02/02/2017','03/02/2017','04/02/2017','05/02/2017'] x = [dt.datetime.strptime(d,'%d/%m/%Y').date() for d in dates] data = np.array([[1,2],[2,5],[3,1],[4,0],[5,5]]) plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y')) plt.gca().xaxis.set_major_locator(mdates.DayLocator()) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.set_title("Plot title...") ax1.set_xlabel('your x label..') ax1.set_ylabel('your y label...') ax1.plot(x,data[:,0], c='r', label='data 1') ax1.plot(x,data[:,1], c='r', label='data 2') plt.gcf().autofmt_xdate() leg = ax1.legend() plt.show() 
      • materiel by figure - matplotlib.org/api/figure_api.html Even in Excel you need to build a graph for more than one action - you need to describe the axes, define the axis labels and data ... here it’s all done, I don’t know what there is much or little - Eugene Bartosh
      • I don't know what your problem is :-) a ['3']. plot () cannot work at all ever. This is how to tell the courier "go" ... where, why ... - Eugene Bartosh
      • @EugeneBartosh, a['3'].plot() is the normal practice for rendering Pandas.DataFrame. Unfortunately, the author of the question forgot to mark the question with the pandas tag. - MaxU February
      • ah, sorry, pandas don't know)) - Eugene Bartosh
      • one
        thanks, and all because the panda was driven out, 3 years ago, it was a deal)) so I didn’t meet her)) but now I know where I live and go too, like a thread - Eugene Bartosh