Reputation: 2493
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
Upvotes: 2
Views: 389
Reputation: 862406
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()
Upvotes: 3