0

I have been trying to insert a column to one of my data sets (A). I have tried to use the pandas function Dataframe.insert, but it keeps on returning None to the data frame (code and results attached below). I have also tried to look online at some of the other examples but have not been able to identify any areas. Could I seek your advice for anything I missed out or code I can input?

I'm using Python 3.9, UTF-8. Thank you in advanced!

>>> import pandas as pd

>>> A = pd.read_csv('input.csv')
#print(A)

>>>      ID      Date  ...       Result Test Date Full Text
0   A  4-Jan-00  ...                    NaN       NaN
1   B  4-Jan-00  ...                    NaN       NaN
2   C  4-Jan-00  ...                    NaN       NaN

>>> B = A.insert(6, "Data Type", 1)

>>> print(B)

>>> None
1
  • try printing A instead of B....insert() method doesn't returns anything so that's why B is None Commented May 31, 2021 at 16:40

1 Answer 1

1

Pandas' insert method, inserts the requested column inplace. It doesn't return anything, however, you have tried to assign the non-existing output to another dataframe. If you print A, you'll see that it has in fact at its 6th index, a column named Data Type with the constant value of 1.

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

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.