小编raj*_*aja的帖子

Python Pandas根据列对行进行计数

如何基于Python熊猫中的一列获取行数。例如,我有一个这样的数据框:

Name         NameTitle    Sex

John         Dr           m
Mona         Dr           f
Mary         Mrs          f
Tom          Mr           m
Jack         Mr           m 
Leila        Ms           f
Soro         Ms           f 
Christi      Ms           f
Mike         Mr           m  
Run Code Online (Sandbox Code Playgroud)

我需要根据性别计算名字标题的数量。所需的输出将是这样的:

NameTitle    Sex    Count

Dr           m      1
Dr           f      1
Mrs          f      1
Mr           m      3
Ms           f      3
Run Code Online (Sandbox Code Playgroud)

rowcount dataframe python-2.7 pandas

5
推荐指数
1
解决办法
4192
查看次数

无法 PIP 安装 Python ftfy 包

当我尝试使用命令在此处安装 ftfy包时, pip install ftfy我在终端中收到以下错误:

Collecting ftfy
  Using cached https://files.pythonhosted.org/packages/d5/60/7b2d5d41ad6c6ebf48316b1c55ccf7c60d126e07f6306be9f254a139bfd1/ftfy-5.4.1.tar.gz
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.org/simple/pytest-runner/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) -- Some packages may not be found!
    Couldn't find index page for 'pytest-runner' (maybe misspelled?)
    Download error on https://pypi.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) -- Some packages may not be found!
    No local packages or working download links found for pytest-runner
    Traceback (most recent call last):
      File "<string>", …
Run Code Online (Sandbox Code Playgroud)

installation pip python-3.5

5
推荐指数
1
解决办法
4869
查看次数

Python Pandas将列中的子字符串替换为另一列中的子字符串

我有一个Python Pandas数据框,如下所示:

Id      Title            URL                                       PosterPath
Id-1    Bruce Almighty   https://www.youtube.com/embed/5VGyTOGxyVA  https://i.ytimg.com/vi/XXXRRR/hqdefault.jpg
Id-2    Superhero Movie  https://www.youtube.com/embed/3BnXz-7-y-o  https://i.ytimg.com/vi/XXXRRR/hqdefault.jpg
Id-3    Taken            https://www.youtube.com/embed/vjbfiOERDYs  https://i.ytimg.com/vi/XXXRRR/hqdefault.jpg
Run Code Online (Sandbox Code Playgroud)

我想将“ PosterPath”列中的“ XXXRRR”子字符串替换为“ URL”列中的“ embed /”字符串之后的子字符串,输出数据框如下所示:

Id      Title            URL                                       PosterPath
Id-1    Bruce Almighty   https://www.youtube.com/embed/5VGyTOGxyVA  https://i.ytimg.com/vi/5VGyTOGxyVA/hqdefault.jpg
Id-2    Superhero Movie  https://www.youtube.com/embed/3BnXz-7-y-o  https://i.ytimg.com/vi/3BnXz-7-y-o/hqdefault.jpg
Id-3    Taken            https://www.youtube.com/embed/vjbfiOERDYs  https://i.ytimg.com/vi/vjbfiOERDYs/hqdefault.jpg
Run Code Online (Sandbox Code Playgroud)

str-replace python-2.7 pandas

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