-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: add examples to DataFrame.insert() #39313
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
Comments
Thanks @sjvdm for the report. I don't think this is a bug since the
indeed passing an numpy array to this function does not result in alignment. alternatively, the Series could be indexed the same. PR enhancing the docs https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.insert.html (maybe with examples) most welcome. |
Hi @simonjayhawkins , You are right! Thanks for the quick response and thanks for the time to evaluate. I had a typo in my original index passed to df and fixing this alligns the indexes correctly.
|
reopening since enhancing the docs is probably worthwhile. |
take |
@sjvdm @simonjayhawkins I guess this issue is not relevant anymore. |
@nofarm3 the docs for insert have indeed been updated since the released docs. but, could still be updated further to clarify the alignment when adding a Series. so maybe could add an example like
|
take |
* DOC: add example to insert (#39313) * DOC: fix style (#39313) * Update pandas/core/frame.py Co-authored-by: nofarmishraki <[email protected]> Co-authored-by: Marco Gorelli <[email protected]>
Code Sample
Output:
Problem description
Issue: StringDtype exhibits strange behaviour when inserting as column. Some elements are inserted as , but evaluates correctly outside of the insert function
Expected Output
Values should be inserted as is.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 3e89b4c
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-240.1.1.el8_3.x86_64
Version : #1 SMP Thu Nov 19 17:20:08 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_ZA.UTF-8
LOCALE : en_ZA.UTF-8
pandas : 1.2.0
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 49.6.0
Cython : 0.29.21
pytest : 6.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : 1.3.22
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
Workaround
Parse to "Values" before inserting. In the example above:
df.insert(loc=0,column='test',value=pd.Series(["one","two","three"]).astype("string").values)
The text was updated successfully, but these errors were encountered: