小编Al_*_*der的帖子

检查项目是否在嵌套列表中

在检查后的简单列表中是微不足道的:

x = [1, 2, 3]

2 in x  -> True
Run Code Online (Sandbox Code Playgroud)

但如果是列表清单,例如:

x = [[1, 2, 3], [2, 3, 4]]

2 in x   -> False
Run Code Online (Sandbox Code Playgroud)

如何才能回归True

python list

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

Excel中的Excel VLOOKUP等效于pandas

我有以下数据框:

               A           B            C
 Index
2001-06-30    100       2001-08-31     (=value of A at date B)
2001-07-31    200       2001-09-30      ...
2001-08-31    300       2001-10-31      ...
2001-09-30    400       2001-11-30      ...
Run Code Online (Sandbox Code Playgroud)

BA一些向前移动的列的日期组成.我想生成C由列A上的值组成的列date B.(最好是在逻辑了Excel VLOOKUP公式将这样做.我不是在寻找用于简单地移位(-2)在这里,因为在realtity之间的偏移BIndex不总是相等).

我试过df.loc['B', 'A']但这很可能是简单化并产生错误.

python pandas

9
推荐指数
1
解决办法
1万
查看次数

根据字符串条件删除列

如何根据名称中的某个字符串删除数据框列?

例:

           house1    house2    chair1  chair2
index
  1         foo       lee       sam      han
  2         fowler    smith     had      sid
  3         cle       meg       mag      mog
Run Code Online (Sandbox Code Playgroud)

我想删除字符串中包含'chair'的列.如何以有效的方式完成?谢谢.

python string dataframe pandas

5
推荐指数
2
解决办法
3147
查看次数

cumsum()在几列上

我想创建以下数据帧:

Index       A        B        C
 a          0        0        0
 b          1       10        0
 c         -1        0      -10
 d          1       20        0
 e          0        0        0
 f         -1        0      -20
 g          0        0        0
 h          1       15        0
 i         -1        0      -15
Run Code Online (Sandbox Code Playgroud)

AB给出.C应通过函数生成,无需迭代.可能就是这种方式:

def generate_C():
    C = np.where(A == -1, << here prior value from B * -1 >>, 0)
    df['C] = C
    return df
Run Code Online (Sandbox Code Playgroud)

我尝试通过cumsum()在列上B,C但没有走远.有什么建议吗?

python dataframe pandas cumsum

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

两个数据点之间的线性插值

我有两个数据点xy:

  x = 5 (value corresponding to 95%)
  y = 17 (value corresponding to 102.5%)
Run Code Online (Sandbox Code Playgroud)

不,我想计算xi应该对应100%的值.

 x = 5 (value corresponding to 95%)
 xi = ?? (value corresponding to 100%)
 y = 17 (value corresponding to 102.5%)
Run Code Online (Sandbox Code Playgroud)

我应该如何使用python执行此操作?

python interpolation dataframe pandas

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

找到不同行中最小的两个单元格

我有以下数据框与列AB.列C应该是前一行的A.shift(1)和当前行的B的最小值:

         A     B     C
Index
  1    100   200    NaN
  2    150   230    100
  3    130   110    110
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法吗?如何使用不属于同一行的单元格构造min()函数?

python pandas

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

标签 统计

python ×6

pandas ×5

dataframe ×3

cumsum ×1

interpolation ×1

list ×1

string ×1