I have a pandas dataframe with 25 rows, and also a list with 5 elements. How do I:
- assign 1st element of the list to first row of the dataframe
- 2nd element of the list to second row
- …
- 1st element to 6th row of dataframe etc
Eg: Need to assign a doctor to each patient sequentially
df:
| Name | Gender |
| ——– | ————– |
| First | Male |
| Second | Female |
| Third | Male |
| Fourth | Male |
| Fifth | Male |
list_doctor = [‘andrea’,’anup’]
Required Output:
| Name | Gender | Doctor |
| ——– | ————– |———|
| First | Male |andrea |
| Second | Female |anup |
| Third | Male |andrea |
| Fourth | Male |anup |
| Fifth | Male |andrea |
Tried with iterrows, but all rows are being assigned to the same name
for index, row in df.iterrows():
for doctor in l_doctor:
print(index, doctor)
df.loc[index,'Assignee'] = doctor