Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting values in DataFrame with timezone-aware index fails using .loc #12502

Closed
kdebrab opened this issue Mar 1, 2016 · 1 comment
Closed
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype

Comments

@kdebrab
Copy link
Contributor

kdebrab commented Mar 1, 2016

In Pandas 0.17.1, setting values in a DataFrame with .loc does not seem the work well in case of timezone-aware indices in combination with a list of columns:

In [1]: import pandas as pd
   ...: start = pd.Timestamp('2015-7-12', tz='utc')
   ...: end = pd.Timestamp('2015-7-12 12:00', tz='utc')
   ...: timestamps = pd.date_range(start, end, freq='H')
   ...: df1 = pd.DataFrame(index=timestamps, columns=['var'])
   ...: df2 = pd.DataFrame(1.2, index=timestamps, columns=['var'])
   ...: df1.loc[:,['var']] = df2
   ...: df1
 Out[1]: 
                           var
2015-07-12 00:00:00+00:00  NaN
2015-07-12 01:00:00+00:00  NaN
2015-07-12 02:00:00+00:00  NaN
2015-07-12 03:00:00+00:00  NaN
2015-07-12 04:00:00+00:00  NaN
2015-07-12 05:00:00+00:00  NaN
2015-07-12 06:00:00+00:00  NaN
2015-07-12 07:00:00+00:00  NaN
2015-07-12 08:00:00+00:00  NaN
2015-07-12 09:00:00+00:00  NaN
2015-07-12 10:00:00+00:00  NaN
2015-07-12 11:00:00+00:00  NaN
2015-07-12 12:00:00+00:00  NaN

Though it does work when replacing ['var'] by 'var':

In [2]: start = pd.Timestamp('2015-7-12', tz='utc')
   ...: end = pd.Timestamp('2015-7-12 12:00', tz='utc')
   ...: timestamps = pd.date_range(start, end, freq='H')
   ...: df1 = pd.DataFrame(index=timestamps, columns=['var'])
   ...: df2 = pd.DataFrame(1.2, index=timestamps, columns=['var'])
   ...: df1.loc[:,'var'] = df2
   ...: df1
Out[2]: 
                           var
2015-07-12 00:00:00+00:00  1.2
2015-07-12 01:00:00+00:00  1.2
2015-07-12 02:00:00+00:00  1.2
2015-07-12 03:00:00+00:00  1.2
2015-07-12 04:00:00+00:00  1.2
2015-07-12 05:00:00+00:00  1.2
2015-07-12 06:00:00+00:00  1.2
2015-07-12 07:00:00+00:00  1.2
2015-07-12 08:00:00+00:00  1.2
2015-07-12 09:00:00+00:00  1.2
2015-07-12 10:00:00+00:00  1.2
2015-07-12 11:00:00+00:00  1.2
2015-07-12 12:00:00+00:00  1.2

Also, it works with a non-timezone-aware index:

In [3]: start = pd.Timestamp('2015-7-12')
   ...: end = pd.Timestamp('2015-7-12 12:00')
   ...: timestamps = pd.date_range(start, end, freq='H')
   ...: df1 = pd.DataFrame(index=timestamps, columns=['var'])
   ...: df2 = pd.DataFrame(1.2, index=timestamps, columns=['var'])
   ...: df1.loc[:,['var']] = df2
   ...: df1
Out[3]: 
                     var
2015-07-12 00:00:00  1.2
2015-07-12 01:00:00  1.2
2015-07-12 02:00:00  1.2
2015-07-12 03:00:00  1.2
2015-07-12 04:00:00  1.2
2015-07-12 05:00:00  1.2
2015-07-12 06:00:00  1.2
2015-07-12 07:00:00  1.2
2015-07-12 08:00:00  1.2
2015-07-12 09:00:00  1.2
2015-07-12 10:00:00  1.2
2015-07-12 11:00:00  1.2
2015-07-12 12:00:00  1.2
@jreback
Copy link
Contributor

jreback commented Mar 1, 2016

dupe of #11365

@jreback jreback closed this as completed Mar 1, 2016
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants