python - 如何删除熊猫(python)中特殊行下的所有行?
问题描述
如何在熊猫(Python)中删除具有一列“练习”的行下的所有行?
数据:
2021.08.16 19:37:15 146242975 XAUEUR buy 0.02 1 517.04 1 517.19 1 519.54 2021.08.16 20:38:30 1 517.15 - 0.12 0.00 0.22
2021.08.16 19:37:15 146242976 XAUEUR buy 0.02 1 517.04 1 517.19 1 522.04 2021.08.16 20:38:30 1 517.15 - 0.12 0.00 0.22
Exercises
2021.08.16 01:02:11 146037881 XAUUSD buy 0.18 / 0.18 market 1 777.72 1 781.47 2021.08.16 01:02:11 filled TP1
...
解决方案
df = pd.DataFrame({'num':[1,2,3,4,'Excercises',6,7,8]})
#First find the row index by filtering the column value
my_index = df.index[df['num'] == 'Exercises'].tolist()[0] # as you my find multiple match, take the first index found by [0]
#my_index = 4
#Then slice the Dataframe and take values into new df
df_new = df[:my_index] # or if you want to exclude that row , then add +1 to my_index
推荐阅读
- python - 如何使用 tensorflow_io 的 IODataset?
- informix - 在 Informix 中选择每第 n 行?
- angular - Angular Reactive form:无法在表格中绑定动作
- php - 如何获取某个数组参数的值并将其放入另一个数组中?
- javascript - 如何有条件地为材质ui TreeView组件设置扩展道具
- reactjs - 如果用户来自浏览器 url 栏,NextJS 重定向不起作用
- vaticle-typedb - 如何从 grakn 控制台中删除键空间?
- php - 如何在复选框中显示回显“选中”编辑?
- html - 想要将一个 CSS 类添加到另一个具有不同属性的 CSS 类中
- scala - 如何实现接受参数化特征的子类型并返回它的scala泛型函数