Skip to content

DataFrame groupby partially drops timezone info (to_csv, in notebook) #7622

Closed
@Poquaruse

Description

@Poquaruse

Hi all,

I've encountered a problem with DataFrames, groupby and timezones.

import pandas as pd
import numpy as np

dt_rng = pd.date_range(start='2014-01-01 00:00', periods = 1000, freq='1s', tz='Europe/Berlin')
df = pd.DataFrame({'a':np.random.randn(1000), 'b': np.random.randn(1000)},index = dt_rng)
df['b'] = df['b'].round()
df.to_csv()

--> Timezones are shown in the csv output, for example 2014-01-01 00:00:00+01:00

Now with resampling:

dt_rng = pd.date_range(start='2014-01-01 00:00', periods = 1000, freq='1s', tz='Europe/Berlin')
df = pd.DataFrame({'a':np.random.randn(1000), 'b': np.random.randn(1000)},index = dt_rng)
df['b'] = df['b'].round()
df.groupby(df['b']).resample('1min').to_csv()

--> 2013-12-31 23:01:00 no timezone info, not even UTC.

However:

dt_rng = pd.date_range(start='2014-01-01 00:00', periods = 1000, freq='1s', tz='Europe/Berlin')
df = pd.DataFrame({'a':np.random.randn(1000), 'b': np.random.randn(1000)},index = dt_rng)
df['b'] = df['b'].round()
df.groupby(df['b']).resample('1min').index.levels[1]

shows: Timezone: Europe/Berlin

So the info seems to be there, but is not exported - even if it was exported before without resampling...

Any ideas?

Thanks and best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions