Every line of 'change column name in 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.
420 def 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
62 def matchColumnNames(df): 63 return df.rename( 64 columns={ 65 "id": "vehicle_id", 66 "heading": "direction", 67 "secsSinceReport": "seconds_since_report", 68 "lat": "latitude", 69 "lon": "longitude", 70 "routeTag": "line" 71 } 72 )
39 def _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)
653 def 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
78 def _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
42 def extractCols(df, colnames): 43 extracted = df[colnames] 44 df.drop(extracted.columns, axis=1, inplace=True) 45 return extracted
80 def _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
2 def convert_columns_dtype(df, old_dtype, new_dtype): 3 """ 4 Parameters 5 ---------- 6 df: pandas.DataFrame 7 8 old_dtype: numpy dtype 9 10 new_dtype: numpy dtype 11 """ 12 changed = [] 13 for column in df.columns: 14 if df[column].dtype == old_dtype: 15 df[column] = df[column].astype(new_dtype) 16 changed.append(column) 17 18 return changed
91 def to_unique(self, column_or_columns): 92 self.__convert_column(column_or_columns, FType.unique, None)
136 def copy_column(self, to, fro): 137 """Copy column data 138 139 Args: 140 fro (str): column name to copy data from 141 to (str): column name to copy to 142 """ 143 logging.debug("copying {} to {}".format(fro, to)) 144 self.df[to] = self.df[fro]