Python中的条件数据帧查询

Python中的条件数据帧查询,python,dataframe,Python,Dataframe,给定一个包含3列的数据帧 C1 C2 C3 1.0 B1678 G 4.5 B1678 K 1.2 B1678 K 1.8 K1567 K 6.9 K1567 G 5.0 G1789 G 4.9 G1789 K 9.0 K1567 G 4.0 B1678 G 在Python中,下面的sql等效语句是什么 select sum(C1) where C2 like 'B%' and C3 like '%K%

给定一个包含3列的数据帧

C1    C2      C3 
1.0   B1678   G
4.5   B1678   K
1.2   B1678   K
1.8   K1567   K
6.9   K1567   G
5.0   G1789   G
4.9   G1789   K
9.0   K1567   G
4.0   B1678   G
在Python中,下面的sql等效语句是什么

select sum(C1) 
where C2 like 'B%'
and C3 like '%K%';

以下是您的做法:

select = df[df["C2"].str.startswith("B") & (df["C3"] == "K")]
summation = select["C1"].sum()

以下是您的做法:

select = df[df["C2"].str.startswith("B") & (df["C3"] == "K")]
summation = select["C1"].sum()
可能的重复可能的重复