6 examples of 'pandas split column by delimiter' in Python

Every line of 'pandas split column by delimiter' 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
4def split_and_expand(df, col, sep):
5 split_col = df[col].str.split(sep).apply(pd.Series, 1).stack()
6 split_col.index = split_col.index.droplevel(-1)
7 split_col.name = col
8 df = df.drop(col, axis=1).join(split_col)
9 df.reset_index(drop=True, inplace=True)
10 return df
197def select_column(df, token):
198 column_name = token.value
199 if "." in column_name:
200 table_name, column_name = column_name.split(".", 1)
201 #TODO: Assert table name is correct
202 #TODO: Catch KeyError exception and raise error saying column does not exist
203 return df[column_name]
253def _split_dataframe(df, dense_columns):
254 """Split a DataFrame by creating groups of the same values for the dense dims."""
255 groups = {name: group for name, group in df.groupby(dense_columns)}
256 groups = convert_dictionary_keys_to_dense_indices(groups)
257
258 return groups
29@staticmethod
30def get_delimiter(df):
31 if df.empty:
32 print('Error: get_delimiter! Got empty df!')
33 pair = df.iloc[-1].pair
34 return '_' if '_' in pair else '-'
37def split(line):
38 """
39 Operator function for splitting a line with csv module
40 """
41 reader = csv.reader(StringIO(line))
42 return reader.next()
166def split(self, row):
167 splitter = (row.startswith('| ') and self._split_from_pipes
168 or self._split_from_spaces)
169 for value in splitter(row):
170 yield value
171 yield '\n'

Related snippets