ee8291
ee8291

Reputation: 565

Cannot shape data in Pandas

I have this line of code which reads a pandas file. Then, I want to define the columns names in the same line of code but it gives me an error. I am not sure how to solve...maybe a syntax? Please advise

Current State: 
ratings = pd.read_csv('ratings.tsv',header=None,sep='\t', encoding= 'latin1')

Desired State: 
rating = pd.read_csv('ratings.tsv', header=None,sep='\t', encoding= 'latin1',['id','age'])

Upvotes: 1

Views: 42

Answers (1)

Scott Boston
Scott Boston

Reputation: 153550

Try, using the names parameter in pd.read_csv:

rating = pd.read_csv('ratings.tsv', 
                     header=None,
                     sep='\t', 
                     encoding= 'latin1',
                     names = ['id', 'age'])

Upvotes: 3

Related Questions