creating vector from df.intertuples

Peter Otten __peter__ at web.de
Mon Apr 17 13:56:52 EDT 2017


Richard Medina wrote:

> I want to create a vector from a dataframe in a loop. Then I want to
> create a new column from this vector.
> 
>     for row in df.itertuples():
>         mm  = str(row.t)  #selecting "t" column
>         nn = get_sec(mm) #this function converts time to seconds
>         df["s"] = nn #I want to add my new vector to a new "s" column in
>         my df
>     print(df.head())    #only gives me the last number in the "nn" column.

I think you need to build the whole column before adding it to the 
DataFrame.

# untested
df["s"] = [get_sec(str(t)) for t in row.t]




More information about the Python-list mailing list