Skip to content

Define column-wise na/default value for merge operations. #1836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gerigk opened this issue Sep 4, 2012 · 2 comments
Closed

Define column-wise na/default value for merge operations. #1836

gerigk opened this issue Sep 4, 2012 · 2 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@gerigk
Copy link

gerigk commented Sep 4, 2012

I find myself often using fillna on a lot of columns after a merge operation and having to cast columns back to their original dtype.
Pseudo code now

data_types = df.dtypes
df_new = merge(df, df_other)
for col in former_int64_columns:
df_new[col] = df_new[col].fillna(0).astype(np.int64)

in some cases I may want a different default value, also for other column types than int64.

An idea would be something like a keyword argument "column_default_values = { 'a': 0, 'b': -1, ...}".

@petehuang
Copy link
Contributor

This issue's last interaction was 4 years ago. In the most recent version of pandas, you just need to call df.fillna(0) instead of iterating through each of the columns. You can also use a dict of values for column-specific fill values.

However, passing a default value into merge is still not supported.

@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Dec 28, 2016
@jreback
Copy link
Contributor

jreback commented Dec 28, 2016

merge columns are pretty good dtype-wise. if there is a more specific example, please open a new issue with a repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants