小编ile*_*l42的帖子

如何读大熊猫中的大型json?

我的代码是:data_review=pd.read_json('review.json') 我的数据review为fllow:

{
    // string, 22 character unique review id
    "review_id": "zdSx_SD6obEhz9VrW9uAWA",

    // string, 22 character unique user id, maps to the user in user.json
    "user_id": "Ha3iJu77CxlrFm-vQRs_8g",

    // string, 22 character business id, maps to business in business.json
    "business_id": "tnhfDv5Il8EaGSXZGiuQGg",

    // integer, star rating
    "stars": 4,

    // string, date formatted YYYY-MM-DD
    "date": "2016-03-09",

    // string, the review itself
    "text": "Great place to hang out after work: the prices are decent, and the ambience is fun. It's a …
Run Code Online (Sandbox Code Playgroud)

python json pandas

8
推荐指数
3
解决办法
5545
查看次数

如何做pd.get_dummies或其他方式?

实际上,我的问题是基于:

是否有更快的方法根据条件更新数据帧列值?

所以,数据应该是:

import pandas as pd
import io
t="""
AV4MdG6Ihowv-SKBN_nB    DTP,FOOD
AV4Mc2vNhowv-SKBN_Rn    Cash 1,FOOD
AV4MeisikOpWpLdepWy6    DTP,Bar
AV4MeRh6howv-SKBOBOn    Cash 1,FOOD
AV4Mezwchowv-SKBOB_S    DTOT,Bar
AV4MeB7yhowv-SKBOA5b    DTP,Bar
"""
data_vec=pd.read_csv(io.StringIO(t),sep='\s{2,}',names=['id','source'])
data_vec
Run Code Online (Sandbox Code Playgroud)

这是data_vec:

    id  source
0   AV4MdG6Ihowv-SKBN_nB    DTP,FOOD
1   AV4Mc2vNhowv-SKBN_Rn    Cash 1,FOOD
2   AV4MeisikOpWpLdepWy6    DTP,Bar
3   AV4MeRh6howv-SKBOBOn    Cash 1,FOOD
4   AV4Mezwchowv-SKBOB_S    DTOT,Bar
5   AV4MeB7yhowv-SKBOA5b    DTP,Bar
Run Code Online (Sandbox Code Playgroud)

如果我想要结果如下:(这意味着如何矢量化多个标签或类别?)

                  _id  source_Cash 1  source_DTOT  source_DTP  Food  Bar
0  AV4MdG6Ihowv-SKBN_nB              0            0        1      1    0
1  AV4Mc2vNhowv-SKBN_Rn              1            0        0      1    0
2  AV4MeisikOpWpLdepWy6              0            0        1      0    1
3 …
Run Code Online (Sandbox Code Playgroud)

python pandas scikit-learn one-hot-encoding

3
推荐指数
1
解决办法
302
查看次数

如何获取自定义间隔中的最后一个日期? - 熊猫

我的例子可能很大,我的代码在这里:

import pandas as pd
import numpy as np
import io
t = """
name     date
a     2005-08-31
a     2005-09-20
a     2005-11-12
a     2005-12-31
a     2006-03-31
a     2006-06-25
a     2006-07-23
a     2006-09-28
a     2006-12-21
a     2006-12-27
a     2007-07-23
a     2007-09-21
a     2007-03-15
a     2008-04-12
a     2008-06-21
a     2008-06-11
b     2005-08-31
b     2005-09-23
b     2005-11-12
b     2005-12-31
b     2006-03-31
b     2006-06-25
b     2006-07-23
b     2006-09-28
b     2006-12-21
b     2006-12-27
b     2007-07-23
b     2007-09-21
b     2007-03-15
b     2008-04-12
b     2008-06-21
b     2008-06-11 …
Run Code Online (Sandbox Code Playgroud)

python time-series pandas

2
推荐指数
1
解决办法
175
查看次数

如何将集合转换为 pandas 中的列表?

我有这样的数据:

name SF
a   {1,23,4,5}
b   {1,3,43,5}
c   {1,23,24,5}
d   {1,23,54,15}
Run Code Online (Sandbox Code Playgroud)

我想让SFset得到list 我期望的输出是:

name SF
a   [1,23,4,5]
b   [1,3,43,5]
c   [1,23,24,5]
d   [1,23,54,15]
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么做呢?

pandas

2
推荐指数
1
解决办法
8053
查看次数