10 examples of 'drop first column pandas' in Python

Every line of 'drop first column pandas' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
39def _drop_col(self, df):
40 '''
41 Drops last column, which was added in the parsing procedure due to a
42 trailing white space for each sample in the text file
43 Arguments:
44 df: pandas dataframe
45 Return:
46 df: original df with last column dropped
47 '''
48 return df.drop(df.columns[-1], axis=1)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

332def dropcols(df, start=None, end=None):
333 """Drop columns that contain NaN within [start, end] inclusive.
334
335 A wrapper around DataFrame.dropna() that builds an easier *subset*
336 syntax for tseries-indexed DataFrames.
337
338 Parameters
339 ----------
340 df : DataFrame
341 start : str or datetime, default None
342 start cutoff date, inclusive
343 end : str or datetime, default None
344 end cutoff date, inclusive
345
346 Example
347 -------
348 df = DataFrame(np.random.randn(10,3),
349 index=pd.date_range('2017', periods=10))
350
351 # Drop in some NaN
352 df.set_value('2017-01-04', 0, np.nan)
353 df.set_value('2017-01-02', 2, np.nan)
354 df.loc['2017-01-05':, 1] = np.nan
355
356 # only col2 will be kept--its NaN value falls before `start`
357 print(dropcols(df, start='2017-01-03'))
358 2
359 2017-01-01 0.12939
360 2017-01-02 NaN
361 2017-01-03 0.16596
362 2017-01-04 1.06442
363 2017-01-05 -1.87040
364 2017-01-06 -0.17160
365 2017-01-07 0.94588
366 2017-01-08 1.49246
367 2017-01-09 0.02042
368 2017-01-10 0.75094
369
370 """
371
372 if isinstance(df, Series):
373 raise ValueError("func only applies to `pd.DataFrame`")
374 if start is None:
375 start = df.index[0]
376 if end is None:
377 end = df.index[-1]
378 subset = df.index[(df.index >= start) & (df.index <= end)]
379 return df.dropna(axis=1, subset=subset)
35@property
36def drop_columns(self):
37 drop_col=self.uni_table.query('Iv<%s'%(self._iv_threshold))
38 return pd.concat([drop_col,self.uni_table[self.uni_table['Iv'].isnull()]])
80def _clean_columns(df, keep_colnames):
81 new_colnames = []
82 for i,colname in enumerate(df.columns):
83 if colname not in keep_colnames:
84 new_colnames.append(i)
85 else:
86 new_colnames.append(colname)
87 return new_colnames
29def _concat(df, type):
30 if df is None:
31 df = pd.DataFrame(_object_blocks[type])
32 else:
33 _df = pd.DataFrame(_object_blocks[type])
34 df = pd.concat([df, _df], sort=True)
35 return df
653def set_index_post_series(df, index_name, drop, column_dtype):
654 df2 = df.drop("_partitions", axis=1).set_index("_index", drop=True)
655 df2.index.name = index_name
656 df2.columns = df2.columns.astype(column_dtype)
657 return df2
78def _clean_column(self, column):
79 if not isinstance(column, (int, str, unicode)):
80 raise ValueError('{} is not a valid column'.format(column))
81 return column in self.df.columns
420def df_column_types_rename(df):
421 result = [df[x].dtype.name for x in list(df.columns)]
422 result[:] = [x if x != 'object' else 'string' for x in result]
423 result[:] = [x if x != 'int64' else 'integer' for x in result]
424 result[:] = [x if x != 'float64' else 'double' for x in result]
425 result[:] = [x if x != 'bool' else 'boolean' for x in result]
426
427 return result
409def temp_remove_fields(df, removeFields):
410
411 tempRemoveFields = list(set(df) & set(removeFields))
412 tempDf = df[tempRemoveFields]
413 df = df.drop(columns=tempRemoveFields)
414
415 return df, tempDf
259def drop_some(df_: pd.DataFrame, thresh: int) -> pd.DataFrame:
260 # thresh is the minimum number of NA, the 1 indicates that columns should be dropped not rows
261 return df_.dropna(1, thresh=thresh)

Related snippets