question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

frequency of time series read with `read_csv`

See original GitHub issue

I f I read a regular time series (with a fixed frequency) with read_csv, the resulting DataFrame has no freuqency.


In [82]: lines = ['2012-07-27T13:%02d, %d' % (min, index) for index, min in enumerate(range(1, 59))]

In [83]: input = StringIO.StringIO('\n'.join(lines))

In [84]: df = pd.read_csv(input, parse_dates=True, index_col=0, names='A')

In [85]: df.index
Out[85]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-07-27 13:01:00, ..., 2012-07-27 13:58:00]
Length: 58, Freq: None, Timezone: None

What I would like to have, is a possibility to set the frequency without resampling (or maybe read_csv could guess a frequency).

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dacoexcommented, Dec 13, 2015

[Edit: corrected code snippet]

So what is the best way to set the frequency directly from the csv file dates?

df = df.asfreq(pd.infer_freq(df.index))

And why can a infer_freq no be part of the read_csv function

1reaction
patricktokeeffecommented, Apr 12, 2013

This should not implemented using a freq argument if the intent is to pass in some numeric value. If the read_csv function is called with parse_dates=True then the date parsing function should attempt to determine the frequency on it’s own. It’s nonsense to expect the frequency to be known and passed to the parsing function. If the user can specify a value for freq they might as well reindex it after loading.

Maybe I could understand adding a determine_freq boolean argument…

Better still (for the user), parse the dates then try and determine the frequency anyway using pd.infer_freq. It took me quite a while to find this function; since it exists, I’m a little puzzled the date parser doesn’t use it by by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Time Series Data in R Importing Comma ...
The easiest way import data in .csv files into R is to use the R function read.csv(). To illustrate, consider the monthly adjusted...
Read more >
Python Pandas: detecting frequency of time series
Show activity on this post. As you can see, the freq is None. I am wondering how can I detect the frequency of...
Read more >
Intro to Time Series Data in R - Managing Date/Time Formats
This tutorial will demonstrate how to import a time series dataset stored in .csv format into R. It will explore data classes for...
Read more >
How to handle time series data with ease? - Pandas
Resample a time series to another frequency​​ The resample() method is similar to a groupby operation: it provides a time-based grouping, by using...
Read more >
Working with Time Series | Python Data Science Handbook
In the final line, we've used one of the standard string format codes for printing dates ( "%A" ), which you can read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found