Skip to content

Unexpected result when combining Series into a DataFrame #1730

Closed
@kdebrab

Description

@kdebrab

Pandas 0.8.1:

import pandas as pd
rng_a = pd.date_range('1/1/2012',periods=4,freq='3H')
rng_b = pd.date_range('1/1/2012',periods=4,freq='4H')
a = pd.Series([0, 1, 2, 3], rng_a)
b = pd.Series([0, 1, 2, 3], rng_b)
pd.DataFrame({'a':a, 'b': b})

unexpectedly returns:

                    a   b
1/1/2012 00:00:00   0   0
1/1/2012 03:00:00   1 NaN
1/1/2012 06:00:00   2 NaN
1/1/2012 09:00:00   3 NaN
1/1/2012 12:00:00 NaN   3

The correct result though is obtained with:

a = pd.Series([0, 1, 2, 3], ['1/1/2012 00:00:00', '1/1/2012 03:00:00', '1/1/2012 06:00:00', '1/1/2012 09:00:00'])
b = pd.Series([0, 1, 2, 3], ['1/1/2012 00:00:00', '1/1/2012 04:00:00', '1/1/2012 08:00:00', '1/1/2012 12:00:00'])
pd.DataFrame({'a':a, 'b': b})

correctly returns:

                    a   b
1/1/2012 00:00:00   0   0
1/1/2012 03:00:00   1 NaN
1/1/2012 04:00:00 NaN   1
1/1/2012 06:00:00   2 NaN
1/1/2012 08:00:00 NaN   2
1/1/2012 09:00:00   3 NaN
1/1/2012 12:00:00 NaN   3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions