0

I have tried various methods to add new column to a Panda dataframe but I get the same result. Methods tried:

call_duration is a list having same number of items as in the data frame.

df['Duration_sec'] = pd.Series(call_duration,index=np.arange(len(df)))

and

df['Duration_sec'] = pd.Series(call_duration,index=df.index)

and

# df['Duration_sec'] = np.array(call_duration)

All three gave the same result as under-enter image description here

I don't understand why the new column is added to new line? And why is there a \ at the end of the first line?

2

2 Answers 2

2

"The new column is not added to a new line"

The DataFrame is wider than the screen and hence continued in next row. In python the \ is usually used to denote join

To add a column, Simply use df.assign

df.assign(Duration_sec=call_duration)
Sign up to request clarification or add additional context in comments.

Comments

1

You can just do

df['Duration_sec'] = call_duration

"\" means the dataframe is wider than your screen and will continue.

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.