inst.to_data_frame() should allow to export index as datetime64
See original GitHub issuehere is an example of script I just had to write for a collaborator:
from pathlib import Path
import pandas as pd
import mne
sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(sample_fname, preload=True)
raw.crop(tmax=10)
df = raw.to_data_frame()
df = df.set_index("time")
index = pd.date_range(start=raw.info['meas_date'],
periods=len(df) + raw.first_samp,
freq=f'{1e3 / raw.info["sfreq"]:0.6f}ms')
df.index = index[raw.first_samp:]
what I have in mind is that we can do
raw.to_data_frame(time_format='date')
to get the time as datetime64. Also I wonder why time is not set as index by default but It’s more a matter of taste
@hoechenberger @dengemann @drammock what do you think?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
python - Convert dataframe index to datetime
It should work as expected. Try to run the following example. import pandas as pd import io data = """value "2015-09-25 00:46" 71.925000...
Read more >Pandas for time series data — tricks and tips - Adrian G
You need to have a datetime index on the df before running this. ... Group by column, apply operation then convert result to...
Read more >pandas.to_datetime — pandas 1.5.2 documentation
Convert argument to datetime. This function converts a scalar, array-like, Series or DataFrame /dict-like to a pandas datetime object. ... Specify a date...
Read more >Part 3 - Introduction to Pandas | ArcGIS API for Python
Let's convert the date columns to datetime64 type using pd.to_datetime() . We will dive into the details of individual date or time columns...
Read more >Convert the column type from string to datetime format in ...
As we can see in the output, the data type of the 'Date' column is object i.e. string. Now we will convert it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is already supported. Quoting the docstring of the
time_format
:Setting time as index automatically is possible by passing
index='time'
. If I run your snippet up throughraw.crop(tmax=10)
and then:hum… I need to think… but i get your point.