0

I need a data frame, which contains just one column which is filled with ones. Here is my code so far.

label_values = np.empty(10)
    label_values.fill(1)
    label_df = pd.DataFrame()
    label_df.insert(column=0, value=label_values.transpose(), allow_duplicates=True)

I get the following error:

    label_df.insert(column=0, value=label_values.transpose(), allow_duplicates=True)
TypeError: insert() missing 1 required positional argument: 'loc'

As far as I see the problem is that the position (row) for the insert is missing. Do I really need to iterate over the array and insert each single value?

Thanks in advance!

0

2 Answers 2

1

Try this!

label_values = np.empty(10)
label_values.fill(1)
label_df = pd.DataFrame()
label_df[0] = label_values
Sign up to request clarification or add additional context in comments.

Comments

1

Slightly shorter than the current proposal

pd.DataFrame(np.ones(10))

Or

pd.DataFrame(10*[1])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.