Every line of 'convert index to 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.
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
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)
43 def convert_input(X, columns=None, deep=False): 44 """ 45 Unite data into a DataFrame. 46 Objects that do not contain column names take the names from the argument. 47 Optionally perform deep copy of the data. 48 """ 49 if not isinstance(X, pd.DataFrame): 50 if isinstance(X, pd.Series): 51 X = pd.DataFrame(X, copy=deep) 52 else: 53 if columns is not None and np.size(X,1) != len(columns): 54 raise ValueError('The count of the column names does not correspond to the count of the columns') 55 if isinstance(X, list): 56 X = pd.DataFrame(X, columns=columns, copy=deep) # lists are always copied, but for consistency, we still pass the argument 57 elif isinstance(X, (np.generic, np.ndarray)): 58 X = pd.DataFrame(X, columns=columns, copy=deep) 59 elif isinstance(X, csr_matrix): 60 X = pd.DataFrame(X.todense(), columns=columns, copy=deep) 61 else: 62 raise ValueError('Unexpected input type: %s' % (str(type(X)))) 63 64 X = X.apply(lambda x: pd.to_numeric(x, errors='ignore')) 65 elif deep: 66 X = X.copy(deep=True) 67 68 return X
83 def _convert_dataframe_1d(idx): 84 _check_idx_1d(idx) 85 idx = idx.iloc[:, 0] if idx.shape[1] == 1 else idx.iloc[0, :] 86 return idx