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

[Bugs] the problem of apply method when Dataframe has a datetime type column #17988

Closed
Lving opened this issue Oct 26, 2017 · 2 comments
Closed

Comments

@Lving
Copy link

Lving commented Oct 26, 2017

my dataframe below:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 18922 entries, 7 to 77733
Data columns (total 4 columns):
user_id       18922 non-null int64
event_id      18922 non-null int64
context       18922 non-null object
created_at    18922 non-null datetime64[ns]
dtypes: datetime64[ns](1), int64(2), object(1)
memory usage: 739.1+ KB

I wrote a function to transform df['context'] to a dict like:

def json_parse(json_str):
    """
    :param user_id:
    :param str:
    :return:
    """
    try:
        juxinli_report = json.loads(json_str)
    except Exception as e:
        print(e)
        juxinli_report = dict()
    if juxinli_report:
        info = {}
        data = juxinli_report.get('data', {})
        for key_1 in data.get('user_gray', {}):
            info[key_1] = data.get('user_gray', {}).get(key_1)
        return info

when I did:

jxl_report[:4].apply(lambda row: json_parse(row['context']), axis=1)

the result was strange, it should be a Series.

user_id	event_id	context	created_at
7	NaN	NaN	NaN	NaN
12	NaN	NaN	NaN	NaN
15	NaN	NaN	NaN	NaN
17	NaN	NaN	NaN	NaN

but if I drop the column created_at or change its type to object, the result is expected, a Series.

jxl_report = jxl_report.drop(['created_at'], axis=1)
# or
# jxl_report['created_at'] = jxl_report['created_at'].astype('str')
7     {'contacts_class1_blacklist_cnt': 2, 'user_pho...
12    {'contacts_class1_blacklist_cnt': 0, 'user_pho...
15    {'contacts_class1_blacklist_cnt': 0, 'user_pho...
17    {'contacts_class1_blacklist_cnt': 0, 'user_pho...

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.13.3
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.9
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Oct 26, 2017

you need a self-contained copy-pastable example that repros, its possible you are seeing #15628

@TomAugspurger
Copy link
Contributor

Let us know if you can provide a reproducible example http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants