为在 Pandas 中调用打印的行设置多个限制

Set Multiple Restrictions for Rows Called to Print in Pandas

import pandas as pd
import numpy as np

#load data
#data file and py file must be in same file path
df = pd.read_csv('cbp15st.txt', delimiter = ',', encoding = 'utf-8- 
sig')

#define load data DataFrame columns

state = df['FIPSTATE']

industry = df['NAICS']

legal_form_of_organization = df['LFO']

suppression_flag = df['EMPFLAG']

total_establishment = df['EST']

establishment_1_4 = df['N1_4']

establishment_5_9 = df['N5_9']

establishment_10_19 = df['N10_19']

establishment_20_49 = df['N20_49']

establishment_50_99 = df['N50_99']

establishment_100_249 = df['N100_249']

establishment_250_499 = df['N250_499']

establishment_500_999 = df['N500_999']

establishment_1000_more = df['N1000']

#use df.loc to parse dataset for partiuclar value types

print(df.loc[df['EMPFLAG']=='A'], df.loc[df['FIPSTATE']==1], 
df.loc[df['NAICS']=='------'])

目前正在使用 df.loc 从 df 列中查找特定值,但会读出包含所有这些值的那些列,而不仅仅是这些值(如 or vs and 语句)

试图找到一种方法对此进行多重限制,以仅获取满足条件 x y 和 z 的列读取。

上方的当前读数:

enter image description here

您可以在指定多个过滤条件时使用 & 运算符,例如:

df1 = df.loc[(df['EMPFLAG']=='A']) & (df['FIPSTATE']==1) & (df['NAICS']=='------')]

print(df1)