1

Note: I have already asked this question but with a much too simple example dataframe. The answers I got for the original dataframe worked very well but not for the one below.

I'm afraid I dont have any code to offer as I'm not really sure how/where to start.

Basically I have a dataframe which has values in some rows but not in others. I'm looking for a method of mapping values from one row/column into another.

Dataframe:

     FirstName     Surname    AccountNum    CScore

0    None          None       123456        70
1    James         Smith      234543        90
2    None          Peters     543533        50
3    Gary          None       948739        100

Basically, I need to replace the 'None values' with names that are unique E.g. column FirstName there are 2 None values; 1 will be David, the other will be Ben. The same is true of the Surname column; 1 None value will be Andrews the other will be Hardy.

So any ideas of how I can handle replacing the None values with unique values/entries would be really appreicated!

Sorry there isn't much to go on.

MRL
  • 389
  • 5
  • 22

1 Answers1

0

So how about something along the lines of:

DF[ DF.Firstname == None ].Firstname = ["David", "Ben"]
DF[ DF.Surname == None ].Surname = ["Andrews", "Hardy"]
Magellan88
  • 2,543
  • 3
  • 24
  • 36
  • A value is trying to be set on a copy of a slice from a DataFrame. Try using **.loc[row_indexer,col_indexer] = value instead** See the caveats in the documentation: http://pandas.pydata.org/pandas- docs/stable/indexing.html#indexing-view-versus-copy self[name] = value – MRL Oct 02 '19 at 10:09