我知道在arcpy中是可能的。了解是否可能在熊猫中发生。
我有以下
develop
我需要选择FY等于或大于2016的所有P.PIN,P.RAD和其他以E开头的物种,并将其放入新的数据框中。
如何完成此任务。我能选择P.PIN和P.RAD,但其他都以E开头;
number_of_rows = self.cur.execute("SELECT * FROM account")
print(number_of_rows)
self.cur.execute("select * FROM account")
if number_of_rows == 1:
row = self.cur.fetchone()
self.lineEdit_1.setText(str(row[0]))
self.lineEdit_2.setText(str(row[1]))
self.lineEdit_3.setText(str(row[2]))
self.lineEdit_4.setText(str(row[3]))
elif number_of_rows == 2:
row = self.cur.fetchone()
self.lineEdit_1.setText(str(row[0]))
self.lineEdit_2.setText(str(row[1]))
self.lineEdit_3.setText(str(row[2]))
self.lineEdit_4.setText(str(row[3]))
row2 = self.cur.fetchone()
self.lineEdit_5.setText(str(row2[0]))
self.lineEdit_6.setText(str(row2[1]))
self.lineEdit_7.setText(str(row2[2]))
self.lineEdit_8.setText(str(row2[3]))
elif number_of_rows == 3:
row = self.cur.fetchone()
self.lineEdit_1.setText(str(row[0]))
self.lineEdit_2.setText(str(row[1]))
self.lineEdit_3.setText(str(row[2]))
self.lineEdit_4.setText(str(row[3]))
row2 = self.cur.fetchone()
self.lineEdit_5.setText(str(row2[0]))
self.lineEdit_6.setText(str(row2[1]))
self.lineEdit_7.setText(str(row2[2]))
self.lineEdit_8.setText(str(row2[3]))
row3 = self.cur.fetchone()
self.lineEdit_9.setText(str(row3[0]))
self.lineEdit_10.setText(str(row3[1]))
self.lineEdit_11.setText(str(row3[2]))
self.lineEdit_12.setText(str(row3[3]))
我们将非常感谢您的帮助。
答案 0 :(得分:0)
逐步进行。但是,您也可以在np.where()
内组合逻辑,只想证明所有条件都已完成。
首先将您的df['FY']
值转换为int类型,以便我们可以使用大于(>)运算符。
>>> df['FY'] = df['FY'].astype(int)
>>> df['flag'] = np.where(df['Species'].isin(['P.PIN', 'P.RAD']), ['Take'], ['Remove'])
>>> df
Species FY flag
0 P.PIN 2002 Take
1 P.PIN 2016 Take
2 V.FOG 2018 Remove
3 V.KOP 2010 Remove
4 E.MON 2009 Remove
5 E.CLA 2019 Remove
6 E.KLI 2017 Remove
7 D.FGH 2016 Remove
8 W.ERT 2018 Remove
9 S.MIX 2018 Remove
10 P.PIN 2016 Take
>>> df['flag'] = np.where((df['FY'] > 2016) & (df['Species'].str.startswith('E')), ['Take'], df['flag'])
>>> df
Species FY flag
0 P.PIN 2002 Take
1 P.PIN 2016 Take
2 V.FOG 2018 Remove
3 V.KOP 2010 Remove
4 E.MON 2009 Remove
5 E.CLA 2019 Take
6 E.KLI 2017 Take
7 D.FGH 2016 Remove
8 W.ERT 2018 Remove
9 S.MIX 2018 Remove
10 P.PIN 2016 Take
>>> new_df = df[df['flag'].isin(['Take'])][['Species', 'FY']]
>>> new_df
Species FY
0 P.PIN 2002
1 P.PIN 2016
5 E.CLA 2019
6 E.KLI 2017
10 P.PIN 2016
希望这会有所帮助:D