6 examples of 'add empty columns to dataframe pandas' in Python

Every line of 'add empty columns to dataframe 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
38def fill_empty(df: pd.DataFrame) -> pd.DataFrame:
39 """Fill the gaps in the 'original' column with values from 'index'
40 Args:
41 df:
42 Returns:
43 """
44 index = df["original"].isnull()
45 df.loc[index, "original"] = df.loc[index, "index"]
46
47 return df
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

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
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)
206def to_pandas(self):
207 return self.dataframe
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
673def _unique(df, columns=None):
674 if isinstance(columns, str):
675 columns = [columns]
676 if not columns:
677 columns = df.columns.tolist()
678 info = {}
679 for col in columns:
680 values = df[col].dropna().values
681 uniques = np.unique(list(_flatten_list(values))).tolist()
682 info[col] = {'count': len(uniques), 'values': uniques}
683 return info

Related snippets