1

Trying to remove a column from a dataframe with simple line of code using panda for python.

The name of the column that i'm trying to remove is "Comments"

import pandas as pd  
location2 = 'datasets_travel_times.csv'     
travelTime_df= pd.read_csv(location2)  
traveltime_df = travelTime_df.drop('Comments',1)  
traveltime_df

It does not give any error; but then I print the dataframe and see that the column "Comments" is still there

1
  • Please provide enough information for us to replicate your code. That way we will be able to better help you. For more information, see minimal reproducible example Commented Oct 13, 2019 at 1:13

1 Answer 1

1

Here are 2 possible ways:-

First Way:-

 travelTime_df.drop(['Comments'], axis=1)

Second way:-

travelTime_df.drop(columns=['Comments'])

Adding link for deep dive:- https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html

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

1 Comment

Third way:- del travelTime_df['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.