2

I got a .csv-file containing lists of time spans like this:

00:00:00.000580;00:00:00.000893;00:00:00.001355;00:00:00.001767;00:00:00.001973;00:00:00.002694; 00:00:00.000069;00:00:00.000689;00:00:00.000873;00:00:00.001097;00:00:00.001920;00:00:00.002563; 00:00:00.000812;00:00:00.001307;00:00:00.001701;00:00:00.002561;00:00:00.003196;00:00:00.003600; 00:00:00.000702;00:00:00.001229;00:00:00.001750;00:00:00.002014;00:00:00.002633;00:00:00.003152; 00:00:00.000776;00:00:00.001774;00:00:00.001989;00:00:00.002115;00:00:00.002504;00:00:00.003228;

...

I'd like to use a jupyter notebook and pandas to read in this file and print a simple graph of the data. This is the code I'm using:

import pandas as pd

inputFile = "D:\\times.csv"

names = ['First', 'Second', 'Third', 'Fourth', 'Fivth', 'Sixth'] 
usecols = [0,1,2,3,4,5]
data = pd.read_csv(inputFile, usecols=usecols, sep=';', header=None, names=names, parse_dates=True)

#data.head()
data.plot.bar()

Whenever I run my notbook, I get an error message

TypeError: Empty 'DataFrame': no numeric data to plot

It seems the csv-file is imported correctly, since I can write out the content of my DataFrame using data.head() and it looks ok.

What do I need to do to plot a graph from my data?

Edit:

This is what I get from data.info():


RangeIndex: 200 entries, 0 to 199
Data columns (total 6 columns):
First 200 non-null object
Second 200 non-null object
Third 200 non-null object
Fourth 200 non-null object
Fivth 200 non-null object
Sixth 200 non-null object
dtypes: object(6)
memory usage: 9.5+ KB

2
  • 1
    What is data.info() telling you? Commented Nov 22, 2016 at 19:51
  • I added the data.info() output into the question. Commented Nov 22, 2016 at 19:55

1 Answer 1

3

You can convert all data to_timedelta and then to total_seconds - integers, so can be plot. Apply is used because to_timedelta works only with Series (columns of df)

data = data.apply(lambda x: pd.to_timedelta(x).dt.total_seconds())

data.plot.bar()

graph

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

2 Comments

Oh, thanks for the quick response! This works! So it looks like DataFrame.plot() only works on "real" numerical values?

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.