简体   繁体   中英

Columns names issues using pandas.read_csv

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

您可以尝试在读取时设置列名称:

df=pd.read_csv(file_loc,sep='\t',header=None,names=["status","message"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM