Home > Mobile >  How to use pandas built-in functions to get dataframes for two month ranges
How to use pandas built-in functions to get dataframes for two month ranges

Time:05-06

I have a dataframe with a date column, which contains the 'month', and I need to create two dataframes from this dataframe. the first one will contain all the listings for which the month values are from 1 to 6, and the second dataframe will contain all the listings for which the month values are from 7 to 12. How can I do this? I have tried this

train_set = data.loc(data['DateTime'] <= 6)
test_set = data.loc(data['DateTime'] > 6)

But, I am getting the following error :

TypeError: unhashable type: 'Series'

Why might I be getting this error? And what is a way that I can achieve what I am trying to do? The column 'DateTime' contains only the month value that I extracted from the original data which was in python datetime format.

CodePudding user response:

Try with correct format of loc[].

train_set = data.loc[data['DateTime'] <= 6]
test_set = data.loc[data['DateTime'] > 6]

CodePudding user response:

Alternatively to loc, you can as well achieve the result using:

train_set = data[data['DateTime'] <= 6]
test_set = data[data['DateTime'] > 6]
  • Related