0

I have a dataframe ready to be used in different models. like below dataframe

Now I want to add another column to this data frame known as "Date time". The column seems ok before adding it. date time column

When I try to add this column to the dataframe through this line df1['date'] = date it shows that there are NaN in the column which is wrong because I have checked and there is not NaN in that. I did "reset index" but again faced the same issue. DF with NAN

2
  • 1
    The index for your date list starts at 2, this means that for index 0 and 1 there is no value. That is why when you merge the date column into your dataframe the first two rows have NaN for the date column Commented Feb 13, 2023 at 10:10
  • 1
    You have a column named “index” rather than just having the index. The column “index” misses 2 two entries (0 and 1) and thus in your end df, the records on index 0 and 1 are empty (or, NaN) Commented Feb 13, 2023 at 10:11

2 Answers 2

1

Your index column starts from 2 that means first 2 indices are missing,

First reset your index by using df.reset_index() see the code line below

df1.reset_index(drop=True)

Then try your code line df1['date'] = date

Sign up to request clarification or add additional context in comments.

Comments

0

try, It might help:

df1['date'] = date['datecolumname']

The add time cannot see it as a single column, which causes an error, there must be 1 column.Correct the date base.

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.