简体   繁体   中英

How to remove certain entries in a data frame based on values within the dataframe

I'm currently coding in Google Colab in Python. I've imported a dataset using its url from ERDDAP, a site used by NOAA for underwater glider data.

I need to take a dataset and remove all entries into the set if they have a depth value greater than 5.

This is what I started with:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

This is what I use to load the dataset:

data = pd.read_csv(url, skiprows=[1], parse_dates=['time'], index_col='time')

Viewing the dataset: data.head()

And this is what it returns:

                     profile_id latitude    longitude   depth   temperature salinity density
time                            
2017-04-24 13:22:53+00:00   1   40.326608   -73.89096   3.71    9.8211  27.334680   1021.01870
2017-04-24 13:22:53+00:00   1   40.326608   -73.89096   4.57    9.8747  28.146105   1021.64660
2017-04-24 13:22:53+00:00   1   40.326608   -73.89096   5.35    9.8602  28.846857   1022.19850
2017-04-24 13:22:53+00:00   1   40.326608   -73.89096   6.45    9.8179  29.451948   1022.68180
2017-04-24 13:22:53+00:00   1   40.326608   -73.89096   7.05    9.8795  29.601862   1022.79175

(just to get an idea of what I'm working with).

I'm not very good at coding so any help would be greatly appreciated. I'm just trying to look for a place to start. Thank you for your time!

这会将数据框更改为仅包含少于 5 的内容

df = df[df.depth < 5]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM