1

I'm using a .csv file imported to an excel sheet with dates and times as:

['2017-09-01 00:00:00.000' '2017-09-01 00:05:00.000'
 '2017-09-01 00:10:00.000' ... '2017-09-30 23:45:00.000'
 '2017-09-30 23:50:00.000' '2017-09-30 23:55:00.000']

and fluxes as :

[3.233,3.928,0,8.333,...]

i've read in the data (in the file it is like

1st col of date and time, 2nd col of flux value

since its from an excel sheet)

How do I get it to plot as all the times per date instead of date vs flux only? I'm getting an extremely reduced plot as a result which is incorrect. I need 2017-09-01 on 00:00:00.000,00:10:00.000, etc. (all available from a .csv file im using, reads incorrectly) vs fluxes at every time instance.

I've just used

col_list = ['time_tag', 'ZPGT10E', ...]
df = pd.read_csv('sep2017.csv', usecols=col_list, skiprows = 717) 
z10edt = df['time_tag'].to_numpy()

to import the data and then to plot:

x = [['2017-09-01', '00:00:00.000'], ['2017-09-01', '00:05:00.000'], ['2017-09-01', '00:10:00.000'], ...['2017-09-01', '00:15:00.000']]
plt.plot(x,avg,color='red',label='average')

But am of course getting the error:

TypeError: unhashable type: 'numpy.ndarray' due to how x is formatted.

What can I do to make the times and dates readable into the plot?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
astralled
  • 21
  • 6

1 Answers1

1
  • Plot the DataFrame directly, do not extract the columns into arrays.
  • See Use index in pandas to plot data
    • df.plot() plots all the other numeric columns against the index.
    • df.plot(y=['col_name']) to specify one of more columns directly, if you don't want all other columns plotted.
  • This uses pandas.DataFrame.plot
import pandas as pd

# read in the data
df = pd.read_csv('sep2017.csv', usecols=col_list, skiprows=717)

# convert the time_tag column to a datetime dtype
df.time_tag = pd.to_datetime(df.time_tag)

# set the time_tag column as the index
df.set_index('time_tag', inplace=True)

# plot the dataframe
df.plot()
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158