vendredi 2 décembre 2016

Autofill column of a DataFrame with random strings until the column is depleted

import numpy as np
from numpy import random
import pandas as pd
from pandas import Series, DataFrame

staff = ['Emelia','Raphael','Mike', 'Peter']

staff_l = []
for i in random.choice(staff, 4):
    staff_l.append(i)
s = Series(staff_l,index=['A','B','C','D'])

dframe = DataFrame(index=['A','B','C','D','E','F'],columns=['Morning','Afternoon'])

dframe.fillna(s)

I want to be able to fill the 'Morning' column with random choice of the names of staff until the column ends and fill the afternoon column also. Since I cant use a list I converted it into a series and still not working. When I use this code dframe.fillna(s) it gives me a NaN column. I cant seem to replace the NaN.




Aucun commentaire:

Enregistrer un commentaire