小编asd*_*asd的帖子

列中除某些词外的标题词

除了列表中的单词,我如何命名所有单词,保留?

keep = ['for', 'any', 'a', 'vs']
df.col
 ``         
0    1. The start for one
1    2. Today's world any
2    3. Today's world vs. yesterday.

Run Code Online (Sandbox Code Playgroud)

预期输出:

     number   title
0     1       The Start for One
1     2       Today's World any
2     3       Today's World vs. Yesterday.


Run Code Online (Sandbox Code Playgroud)

我试过

df['col'] = df.col.str.title().mask(~clean['col'].isin(keep))
Run Code Online (Sandbox Code Playgroud)

python python-3.x pandas

15
推荐指数
2
解决办法
562
查看次数

从数据框中删除布尔行

如何快速删除 A、B 和 C 均为假的行?我试过:

df3 = df[~(~(df['A'])& ~(df['B']) & ~(df['C']) )]
df3
   com     A        B           C
0  as     TRUE    FALSE       FALSE
1  da     TRUE    FALSE       FALSE

Run Code Online (Sandbox Code Playgroud)

python dataframe python-3.x pandas

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

使用前一行进行迭代

如何使用迭代类型的规则创建 col2?

col2 = col1 + 0.1(col2's previous value). If there is no previous value (here in 20 Dec 2019), then col2 should equal col1

df
  date      col1   
2019-12-20   10      
2019-12-27   3       
2020-01-03   7

Run Code Online (Sandbox Code Playgroud)

预期产出

  date      col1  col2  
2019-12-20   10     10   (no previous value, so equal col1)
2019-12-27   3      4    (3+0.1*10)
2020-01-03   7      7.4  (7+0.1*4)
Run Code Online (Sandbox Code Playgroud)

python python-3.x pandas

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

如何在pandas中使用country_converter将国家/地区代码转换为名称

df
         Date        Value CODE
0      2020-03-12      7  AFG
1      2020-03-11      7  AFG
...
Run Code Online (Sandbox Code Playgroud)

我如何从代码生成国家/地区?我尝试从 CODE 变量生成代码

import country_converter as coco
df['country'] = df['CODE'].apply(coco.convert)
Run Code Online (Sandbox Code Playgroud)
Actual Output:
         Date        Value CODE  country
0      2020-03-12      7  AFG     AFG  
1      2020-03-11      7  AFG     AFG 
Run Code Online (Sandbox Code Playgroud)
Expected Output:
         Date        Value CODE  country
0      2020-03-12      7  AFG     Afghanistan  
1      2020-03-11      7  AFG     Afghanistan  
Run Code Online (Sandbox Code Playgroud)

python country-codes dataframe python-3.x pandas

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

从 AF 列开始读入 excel

如何从 AF 列及以后读取 Excel 文件?我不知道最后一列字母名称,而且文件太大,无法不断检查。

df = pd.read_excel(r"Documents\file.xlsx", usecols="AF:")
Run Code Online (Sandbox Code Playgroud)

python excel python-3.x pandas

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

标签 统计

pandas ×5

python ×5

python-3.x ×5

dataframe ×2

country-codes ×1

excel ×1