datadave / GADS9-NYC-Spring2014-Students

Student repo for Spring 2014 Data Science Course at GA NYC
4 stars 22 forks source link

question on problem set.. #52

Closed deeps17 closed 10 years ago

deeps17 commented 10 years ago

I wasn't clear on the problem stmt in this question and what I am supposed to do This is from the independent practice exercise:

write several functions to apply to the data frame that attempt to organize the data set using strings instead of floats, like our short_or_long function from lecture. Use this to best summarize your data.

Can you help clarify?

podopie commented 10 years ago

Sure, @deeps17. In the lecture we briefly talked about how you can apply functions to a column, ie:

df['new_column'] = df['column'].apply(a_function)

Here, the goal is to simplify the data set, so you have text like "text_petal_width" == short/long, etc.

Does that help?

deeps17 commented 10 years ago

@podopie - Ah..Got it! thanks..

podopie commented 10 years ago

Cool. An example would be:

def text_petal_length(x):
  return 'long' if x > 1 else 'short'

iris['PetalLengthTXT'] = iris['PetalLength'].apply(text_petal_length)

And then you'll have a new column that is either 'long' or 'short'.