You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Series.replace() should potentially raise an exception if an invalid argument is given? I am new to pandas and this is more of a question. This is a user error on my part, but possible improvement to replace.
df=pd.DataFrame(
{
'one': ['1','1 ','10'],
'two': ['1 ', '20 ', '30 ']
})
# createsonetwo011112021030# I intentionally added a space in df.one. So df.one.value_counts() results in1110111# I want to strip the spaces around all values in df.one # so that value_counts() only has 1 and 10 with values 2 and 1 respectively. # The following does not work.df.one.replace(lambdax: x.strip(), inplace=True)
Problem description
Series.replace() accepts "str, regex, list, dict, Series, numeric, or None". So I understand why the above does not work. But as @toobaz pointed out on gitter, when a lambda is passed, replace should probably raise an error?
Expected Output
Raises TypeError
Output of pd.show_versions()
[paste the output of pd.show_versions() here below this line]
@gfyoung: forked the codebase and reading "Contributing to Pandas" now. Is this a beginner friendly PR? I would like to contribute if it is. Thank you.
This is one is not hard, but if you want an even more beginner friendly one, take a look for instance at #18589 . Or you can get the list of easy issues and pick the one you prefer.
@lidderupk : There is very much do-able as a beginner. Feel free to ask questions if you're unclear on anything. If you get stuck, submit what you have as a PR, and we can help you out.
Series.replace() should potentially raise an exception if an invalid argument is given? I am new to pandas and this is more of a question. This is a user error on my part, but possible improvement to replace.
Problem description
Series.replace() accepts
"str, regex, list, dict, Series, numeric, or None"
. So I understand why the above does not work. But as @toobaz pointed out on gitter, when a lambda is passed, replace should probably raise an error?Expected Output
Raises TypeError
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 36.3.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.8.0
bs4: None
html5lib: 0.999999999
sqlalchemy: 1.1.14
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.8.1
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: