Reputation: 63
I have a data frame where each of the rows (there are 2 rows total) are currently filled with 0's. Row 1 has three 0's and Row 2 has three 0's. I also have values that I have calculated using a loop and stored in a list. List 1 has three values and List 2 has three values. I need to replace the 0's in row 1 of my data frame with the three different values in List 1. I need to do the same thing with row 2 and List two.
I have really tried to read through the forums and find some code that applies but due to my beginner's knowledge, I am having difficulty applying any kind of code. I would greatly appreciate being pointed in the right direction.
For example, say Row 1 is 0,0,0 in my data frame and List 1 is 1,2,3, After running the necessary code, I would expect Row 1 to be updated to 1,2,3.
Upvotes: 0
Views: 69
Reputation: 3908
If you're replacing every value anyway why don't you just replace the whole DataFrame?
vals = [[1,2,3],[4,5,6]]
column_nms = ["col1", "col2", "col3"]
pd.DataFrame(vals, columns=column_nms)
Output:
col1 col2 col3
0 1 2 3
1 4 5 6
Upvotes: 1