私はPythonの新機能です。私は以下のフィルタリングをしたいと思いますが、最初の条件だけが適用され、他の条件は無視されます。どこが間違っているのか教えていただけますか?ここで が私のデータである:あなたのケースのために最初の条件のみが適用されます
** Exponentiation (raise to the power)
~ + - Ccomplement, unary plus and minus (method names for the last two are [email protected] and [email protected])
*/% // Multiply, divide, modulo and floor division
+ - Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'td>
^ | Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += *= **= Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators
import pandas as pd
census_df = pd.read_csv('census.csv')
census_df.head()
census_df
val1=census_df['POPESTIMATE2015']
val2=census_df['POPESTIMATE2014']
def answer_one():
return census_df[val1>val2 & (census_df['REGION']==1 | (census_df['REGION']==2) & (census_df['CTYNAME'].str.len=='Washington')) ]
answer_one()
返信いただきありがとうございますが、なぜ最初の条件のみが適用され、もう1つは自分のコードに適用できないのですか。私は正しい演算子を使用したと思います。 –
再現性を高めるためにデータの例を挙げることはできますか?最初の条件は括弧で囲む必要があることに注意してください。 – Psidom
質問に自分のデータを追加しました。たとえばここではcensus_df ['CTYNAME']。str.len == 'Washington'、適用されません。 –