0

I am pretty new to python. I am trying to import the SMSSpam Collection Data using pandas read_csv module. I The import went went. But as the file does not have header I tried to include columns names(variables names : "status" and "message" and ended up with empty file. Here is my code:

import numpy as np
import pandas as pd
file_loc="C:\Users\User\Documents\JP\SMSCollection.txt"
df=pd.read_csv(file_loc,sep='\t')

The above code works well I got the I got the 5571 rows x 2 columns]. But when I add columns using the following line of code

df.columns=["status","message"]

I ended up with an empty df Any help on this ? Thanks

1
  • Are you trying to rename existing columns in the dataframe or add new columns to the dataframe? Commented Aug 7, 2018 at 10:38

1 Answer 1

1

You could try to set the column names at read time:

df=pd.read_csv(file_loc,sep='\t',header=None,names=["status","message"])
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.