Python Forum
Update value in sliced dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update value in sliced dataframe
#2
sw.loc[(sw['x']=='M'), 'v']
This is a pandas series (with one value) and you can not assign this to your cell.
Just make it a value.
df.loc[(df['b'] == 'M') & (df['c'].isnull()), 'c'] = sw.loc[(sw['x']=='M'), 'v'].values
df.loc[(df['b'] == 'B') & (df['c'].isnull()), 'c'] = sw.loc[(sw['x']=='B'), 'v'].values
Output:
a b c 0 A B 15.2 1 Z M 1.7 2 A B 66.6 3 Z B 16.8 4 Z M 99.9 5 A M 99.9 6 Z B 66.6
Reply


Messages In This Thread
Update value in sliced dataframe - by bobopt - Nov-12-2019, 01:33 PM
RE: Update value in sliced dataframe - by ThomasL - Nov-12-2019, 07:29 PM
RE: Update value in sliced dataframe - by bobopt - Nov-13-2019, 07:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,695 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Adding Sliced Positions Gizzmo28 1 1,608 Nov-05-2020, 02:46 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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