missing-data

Replace dots in a float column with nan in Python

不羁的心 提交于 2020-12-25 18:14:02
问题 I have a data frame df like this df = pd.DataFrame([ {'Name': 'Chris', 'Item Purchased': 'Sponge', 'Cost': 22.50}, {'Name': 'Kevyn', 'Item Purchased': 'Kitty Litter', 'Cost': '.........'}, {'Name': 'Filip', 'Item Purchased': 'Spoon', 'Cost': '...'}], index=['Store 1', 'Store 1', 'Store 2']) I want to replace the missing values in 'Cost' columns to np.nan . So far I have tried: df['Cost']=df['Cost'].str.replace("\.\.+", np.nan) and df['Cost']=re.sub('\.\.+',np.nan,df['Cost']) but neither of

Replace dots in a float column with nan in Python

自作多情 提交于 2020-12-25 18:11:53
问题 I have a data frame df like this df = pd.DataFrame([ {'Name': 'Chris', 'Item Purchased': 'Sponge', 'Cost': 22.50}, {'Name': 'Kevyn', 'Item Purchased': 'Kitty Litter', 'Cost': '.........'}, {'Name': 'Filip', 'Item Purchased': 'Spoon', 'Cost': '...'}], index=['Store 1', 'Store 1', 'Store 2']) I want to replace the missing values in 'Cost' columns to np.nan . So far I have tried: df['Cost']=df['Cost'].str.replace("\.\.+", np.nan) and df['Cost']=re.sub('\.\.+',np.nan,df['Cost']) but neither of

Replace dots in a float column with nan in Python

随声附和 提交于 2020-12-25 18:11:38
问题 I have a data frame df like this df = pd.DataFrame([ {'Name': 'Chris', 'Item Purchased': 'Sponge', 'Cost': 22.50}, {'Name': 'Kevyn', 'Item Purchased': 'Kitty Litter', 'Cost': '.........'}, {'Name': 'Filip', 'Item Purchased': 'Spoon', 'Cost': '...'}], index=['Store 1', 'Store 1', 'Store 2']) I want to replace the missing values in 'Cost' columns to np.nan . So far I have tried: df['Cost']=df['Cost'].str.replace("\.\.+", np.nan) and df['Cost']=re.sub('\.\.+',np.nan,df['Cost']) but neither of

Python: create a new column from existing columns

笑着哭i 提交于 2020-12-02 06:59:40
问题 I am trying to create a new column based on both columns. Say I want to create a new column z, and it should be the value of y when it is not missing and be the value of x when y is indeed missing. So in this case, I expect z to be [1, 8, 10, 8] . x y 0 1 NaN 1 2 8 2 4 10 3 8 NaN 回答1: The new column 'z' get its values from column 'y' using df['z'] = df['y'] . This brings over the missing values so fill them in using fillna using column 'x' . Chain these two actions: >>> df['z'] = df['y']

Python: create a new column from existing columns

此生再无相见时 提交于 2020-12-02 06:57:46
问题 I am trying to create a new column based on both columns. Say I want to create a new column z, and it should be the value of y when it is not missing and be the value of x when y is indeed missing. So in this case, I expect z to be [1, 8, 10, 8] . x y 0 1 NaN 1 2 8 2 4 10 3 8 NaN 回答1: The new column 'z' get its values from column 'y' using df['z'] = df['y'] . This brings over the missing values so fill them in using fillna using column 'x' . Chain these two actions: >>> df['z'] = df['y']

Python: create a new column from existing columns

北城以北 提交于 2020-12-02 06:57:28
问题 I am trying to create a new column based on both columns. Say I want to create a new column z, and it should be the value of y when it is not missing and be the value of x when y is indeed missing. So in this case, I expect z to be [1, 8, 10, 8] . x y 0 1 NaN 1 2 8 2 4 10 3 8 NaN 回答1: The new column 'z' get its values from column 'y' using df['z'] = df['y'] . This brings over the missing values so fill them in using fillna using column 'x' . Chain these two actions: >>> df['z'] = df['y']