Skip to content

Instantly share code, notes, and snippets.

@ChaitanyaBaweja
Created July 10, 2020 08:08
Show Gist options
  • Save ChaitanyaBaweja/968ff8f454a68be87c7efcfc73eeacd1 to your computer and use it in GitHub Desktop.
Save ChaitanyaBaweja/968ff8f454a68be87c7efcfc73eeacd1 to your computer and use it in GitHub Desktop.
import pandas as pd
missing_value_formats = ["n.a.","?","NA","n/a", "na", "--"]
df = pd.read_csv("employees.csv", na_values = missing_value_formats)
def make_int(i):
try:
return int(i)
except:
return pd.np.nan
# apply make_int function to the entire series using map
df['Salary'] = df['Salary'].map(make_int)
print(df['Salary'].head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment