LMLPP
LMLPP

Reputation: 105

how to append a row from one dataframe to a new dataframe

I am trying to identify rows from one dataframe that meet my date criteria in a specific element and then append them to a new dataframe. I have the identification down, but am having some trouble appending the data to a new dataframe. "yesterday" is a string containing yesterday's date.

    for x in df1.datecompare:
        index += 1
        if x == yesterday:
            dfnew.append(df1.ix[index])

Error I am getting

TypeError: append() missing 1 required positional argument: 'other'

Thanks for the help!

Upvotes: 0

Views: 2429

Answers (1)

root
root

Reputation: 33783

IIUC, append shouldn't be necessary for what you're trying to do. You should be able to do it with boolean indexing:

dfnew = df1[df1.datecompare == yesterday].copy()

In general, iterating over a DataFrame will be much slower than doing a vectorized operation like what I've done above.

Upvotes: 1

Related Questions