Suppose to have two lists, namely indexes
and values
of the same lenght.
I want to fill a DataFrame column, e.g. df["Values"]
using these lists, in particular by assigning values[0]
to all rows with index bewteen 0
and indexes[0]
, then values[1]
to all rows with index bewteen indexes[0
and indexes[1]
and so on…
At this point I was only able to get this result by iterating over all the dataframes with the df.iterrows()
method, but this is rather slow when the size of the dataframe (csv) is about 20 MB.
Is there an elegant way to get the same result without using a for loop but a pandas method or similar?
Grufoony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.