4 examples of 'pandas dataframe reorder columns' in Python

Every line of 'pandas dataframe reorder columns' 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
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)
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]
427 return result
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
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

Related snippets