Issue
I have these two datasets.
! curl -O https://raw.githubusercontent.com/msu-cmse-courses/cmse202-S21-student/master/data/Dataset.data
! curl -O https://raw.githubusercontent.com/msu-cmse-courses/cmse202-S21-student/master/data/Dataset.spec
So I read the data in using
import pandas as pd
data = pd.read_csv("Dataset.data", header = None)
Then I want to make column titles for the Dataset.data since it doesn't have any, just the rows with the data for each snail.
I tried using
data.columns = ['sex','length','diameter','height','whole_weight','shucked_weight','viscera_weight','shell_weight','rings']
to add it to the data set but it gives me the error:
Length mismatch: Expected axis has 1 elements, new values have 9 elements
Can anyone help me I just want my data to have these column titles in it. Currently it has no column titles just numbers
Cheers.
Solution
Your data is delimited by space, but read_csv
defaults to comma, so you need to specify the delimiter manually:
data = pd.read_csv('Dataset.data', delimiter=' ', header=None)
data.columns = ['sex','length','diameter','height','whole_weight','shucked_weight','viscera_weight','shell_weight','rings']
data.head(2)
sex | length | diameter | height | whole_weight | shucked_weight | viscera_weight | shell_weight | rings | |
---|---|---|---|---|---|---|---|---|---|
0 | M | 0.455 | 0.365 | 0.095 | 0.5140 | 0.2245 | 0.1010 | 0.15 | 15 |
1 | M | 0.350 | 0.265 | 0.090 | 0.2255 | 0.0995 | 0.0485 | 0.07 | 7 |
Answered By - tdy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.