Reputation: 447
I have a Dataframe and I am trying to apply a filter as below:
df['flag'] = df[df['aging'].str.contains('5 days')]
But it returns the below error:
ValueError: Wrong number of items passed 3, placement implies 1
Given below is how my Dataframe looks like
id,date,current_date,aging
101,2018-12-01,2018-12-05,-5 days +15:34:11.000000000
102,2018-12-02,2018-12-05,-4 days +21:15:28.000000000
103,2018-12-03,2018-12-05,-3 days +15:43:06.000000000
104,2018-12-04,2018-12-05,-2 days +01:21:24.000000000
105,2018-12-05,2018-12-05,-1 days +01:21:14.000000000
Upvotes: 0
Views: 256
Reputation: 1661
You can filter your df without creating a new column :
print(df[df['aging'].str.contains('5 days')])
If you want to create a new column, you can do so :
df['Flag'] = df['aging'].str.contains('5 days')
The problem with your code is that you both filter and create a new column in the same time.
Upvotes: 1