0

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.

dacoda007
  • 63
  • 1
  • 2
  • 7
  • Possible duplicate of [Python pandas: fill a dataframe row by row](https://stackoverflow.com/questions/17091769/python-pandas-fill-a-dataframe-row-by-row) – Valentino Jun 18 '19 at 21:54

1 Answers1

1

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
Ian
  • 3,605
  • 4
  • 31
  • 66
  • I should have clarified that I have additional columns within the data frame. However, I was able to adjust my code with what you gave and make it work. Thank you!!! – dacoda007 Jun 19 '19 at 00:15