Python Forum
Pandas copying wrong values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas copying wrong values
#2
If we doesn't define ignore_index parameter, the concat/append will add second dataframe rows with the original index numbers it had, thus the new added rows have same index again which start with 0.


import pandas as pd
 
foo = pd.concat([pd.DataFrame({'foo': [10,20]}), pd.DataFrame({'foo': [30,40]})],ignore_index=True)
bar = pd.DataFrame({'bar': [1, 2, 3, 4]})
 
foo["bar"] = bar["bar"]
 
print((foo["bar"].values == bar["bar"].values).all())
print(foo)
Output:
True foo bar 0 10 1 1 20 2 2 30 3 3 40 4
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply


Messages In This Thread
Pandas copying wrong values - by vmarg - Jan-05-2020, 10:52 PM
RE: Pandas copying wrong values - by sandeep_ganga - Jan-06-2020, 06:30 AM
RE: Pandas copying wrong values - by vmarg - Jan-06-2020, 09:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assigning conditional values in Pandas Scott 3 795 Dec-19-2023, 03:10 AM
Last Post: Larz60+
Question How does one clean a populated table in MySQL/MariaDB? Copying values across tables? BrandonKastning 2 1,571 Jan-17-2022, 05:46 AM
Last Post: BrandonKastning
  PANDAS: DataFrame | Saving the wrong value moduki1 0 1,549 Jan-10-2022, 04:42 PM
Last Post: moduki1
  pandas: Compute the % of the unique values in a column JaneTan 1 1,777 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,252 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  Pandas + Groupby + Filter unique values JosepMaria 1 2,873 Jun-15-2020, 08:15 AM
Last Post: JosepMaria
  sort values of a column pandas karlito 2 2,497 Oct-22-2019, 06:11 AM
Last Post: karlito
  Pandas Import CSV count between numerical values within 1 Column ptaylor520 3 2,648 Jul-16-2019, 08:13 AM
Last Post: ptaylor520
  Custom timeinterval converted to hourly values using Pandas? SinPy 1 2,782 Jun-07-2019, 05:06 AM
Last Post: heiner55
  Splitting values in column in a pandas dataframe based on a condition hey_arnold 1 4,168 Jul-24-2018, 02:18 PM
Last Post: hey_arnold

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020