10 examples of 'pandas fillna with another column' in Python

Every line of 'pandas fillna with another column' 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
114def panel_fillna(panel, type="bfill"):
115 """
116 fill nan along the 3rd axis
117 :param panel: the panel to be filled
118 :param type: bfill or ffill
119 """
120 frames = {}
121 for item in panel.items:
122 if type == "both":
123 frames[item] = panel.loc[item].fillna(axis=1, method="bfill").\
124 fillna(axis=1, method="ffill")
125 else:
126 frames[item] = panel.loc[item].fillna(axis=1, method=type)
127 return pd.Panel(frames)
19def fill_missing_values(df_data):
20 """Fill missing values in data frame, in place."""
21 df_data.fillna(method="ffill", inplace="True")
22 df_data.fillna(method='bfill', inplace="True")
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)
3169def hpat_pandas_series_dropna_impl(self, axis=0, inplace=False):
3170 # generate Series index if needed by using SeriesType.index (i.e. not self._index)
3171 na_data_arr = hpat.hiframes.api.get_nan_mask(self._data)
3172 data = self._data[~na_data_arr]
3173 index = self.index[~na_data_arr]
3174 return pandas.Series(data, index, self._name)
2413def combine_first(self, other):
2414 """Combine two Datasets, default to data_vars of self.
2415
2416 The new coordinates follow the normal broadcasting and alignment rules
2417 of ``join='outer'``. Vacant cells in the expanded coordinates are
2418 filled with np.nan.
2419
2420 Parameters
2421 ----------
2422 other : DataArray
2423 Used to fill all matching missing values in this array.
2424
2425 Returns
2426 -------
2427 DataArray
2428 """
2429 out = ops.fillna(self, other, join="outer", dataset_join="outer")
2430 return out
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
580def sdc_fillna_int_impl(self, inplace=False, value=None):
581 return copy(self)
332def dropcols(df, start=None, end=None):
333 """Drop columns that contain NaN within [start, end] inclusive.
334
335 A wrapper around DataFrame.dropna() that builds an easier *subset*
336 syntax for tseries-indexed DataFrames.
337
338 Parameters
339 ----------
340 df : DataFrame
341 start : str or datetime, default None
342 start cutoff date, inclusive
343 end : str or datetime, default None
344 end cutoff date, inclusive
345
346 Example
347 -------
348 df = DataFrame(np.random.randn(10,3),
349 index=pd.date_range('2017', periods=10))
350
351 # Drop in some NaN
352 df.set_value('2017-01-04', 0, np.nan)
353 df.set_value('2017-01-02', 2, np.nan)
354 df.loc['2017-01-05':, 1] = np.nan
355
356 # only col2 will be kept--its NaN value falls before `start`
357 print(dropcols(df, start='2017-01-03'))
358 2
359 2017-01-01 0.12939
360 2017-01-02 NaN
361 2017-01-03 0.16596
362 2017-01-04 1.06442
363 2017-01-05 -1.87040
364 2017-01-06 -0.17160
365 2017-01-07 0.94588
366 2017-01-08 1.49246
367 2017-01-09 0.02042
368 2017-01-10 0.75094
369
370 """
371
372 if isinstance(df, Series):
373 raise ValueError("func only applies to `pd.DataFrame`")
374 if start is None:
375 start = df.index[0]
376 if end is None:
377 end = df.index[-1]
378 subset = df.index[(df.index >= start) & (df.index <= end)]
379 return df.dropna(axis=1, subset=subset)
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
813def merge(old_cols, new_cols):
814 return old_cols + new_cols

Related snippets