Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Mapping and Analyzing a Data Set in Pandas

Give Feedback

In order to do your analysis, you may come across columns, which are not in the correct format for further evaluations. Therefore, you’ll learn in this lesson how to convert a column into a different data type and format by using the map() function.

Donna van Wyk on Nov. 16, 2019

All 4 fields are showing as object now. ? I downloaded as a csv. FG and FGA are int64 in your tutorial though.

Orlando Viera on Dec. 22, 2019

For Python 3.7 use the following line: temp.MP = temp.loc[:][‘MP’].map(str_to_seconds)

Orlando Viera on Dec. 22, 2019

You can also use temp.loc[:][‘MP’] = temp.loc[:][‘MP’].map(str_to_seconds)

Kevin Walsh on Feb. 26, 2020

i had the same issue. WHen i ran the dtype command, all of the items came back as object. I tried to go to the CSV file and change to number format, but, no luck. With the attempted field goals and made field goals as object, i can’t do the follow on math or comparison. Is there a way to ensure that when you are importing CSV files into dataframe, you can get the information as integers or floating instead of objects?

Ricky White RP Team on Feb. 27, 2020

Hi Kevin. I’m no Pandas expert, so I asked one to help answer your question. You can use the converters attribute to specify the type when loading your data from a CSV. Here’s the docs:

Tomasz Zajac on March 12, 2020

Thanks for the hint on converters Ricky! I was stuck with some <class ‘str’> in the MP column. Once I had this str_to_seconds function defined, adding an option to read_csv did the job for me finally.

data = pd.read_csv('kevin.csv', names=columns, skiprows=1, converters={'MP':str_to_seconds})

I used skiprows because there were column names in the first line in my csv file.

Ranit Pradhan on April 3, 2020

In Python 3 when I’m using

temp.MP= temp.loc[:][‘MP’].map(str_to_seconds)

Value error is occuring

ValueError: time data ‘Inactive’ does not match format ‘%M:%S’

zbigniewsztobryn on April 26, 2020

I have question about this line:

datetime.timedelta(minutes=minutes.tm_min, secons=minutes.tm_sec).total_seconds()

I completely don’t get how does varible minutes.tm_min gets data out of previous line. Is it predefined somehow?

piotrjubkepka on April 26, 2020

Hi, my problems is every column is Object. Somebody know hot to fix?

MP     object
FG     object
FGA    object
dtype: object

glaucorolim on May 11, 2020

I was having a object type for all variables as well and I simply deleted the last row of the kevin.csv (a lot of strange values…) all is fine now. best!

bwaspe on May 26, 2020

Agree - delete last row of csv with “inactive” and row 0 if you have column names and you will get int64.

bwaspe on May 26, 2020

I also get this error running line 49

ValueError: time data ‘2439.0’ does not match format ‘%M:%S’

Become a Member to join the conversation.