Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
added 6 characters in body
Source Link
Sociopath

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUETRUE when heavy rain indicators are present and light rain indicator to be TRUETRUE when light rain indicators are present

Someone suggested to use isinisin (and then deleted the post) but I cannot type the exact expression, so for heavy rain indicator for eg I want all values beginning with Rain, to be in heavy indicator column and so on. Pls answer accordingly

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

Someone suggested to use isin (and then deleted the post) but I cannot type the exact expression, so for heavy rain indicator for eg I want all values beginning with Rain, to be in heavy indicator column and so on. Pls answer accordingly

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

Someone suggested to use isin (and then deleted the post) but I cannot type the exact expression, so for heavy rain indicator for eg I want all values beginning with Rain, to be in heavy indicator column and so on. Pls answer accordingly

added 241 characters in body
Source Link
noob

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

Someone suggested to use isin (and then deleted the post) but I cannot type the exact expression, so for heavy rain indicator for eg I want all values beginning with Rain, to be in heavy indicator column and so on. Pls answer accordingly

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

Someone suggested to use isin (and then deleted the post) but I cannot type the exact expression, so for heavy rain indicator for eg I want all values beginning with Rain, to be in heavy indicator column and so on. Pls answer accordingly

Source Link
noob

TypeError: unhashable type: 'list' pandas python

df is the database with weather as column

 Weather
 Rain, freezing cold
 Rain, and thunder
 Thunderstorm, and dust
 Drizzle, for half an hour
 Drizzle, for sometime
 Rain, non stop
 Slight rain

Code

heavy_rain_indicator = ['Rain,','Thunderstorm,',]
light_rain_indicator = ['Drizzle,','Slight rain']

df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))
df['Light Rain Indicator'] = (df['Weather'].str.contains(light_rain_indicator))

Expected output:

 Weather                  Heavy Rain Indicator    Light Rain Indicator
 Rain, freezing cold         TRUE                      FALSE
 Rain, and thunder           TRUE                      FALSE
 Thunderstorm, and dust       TRUE                      FALSE
 Drizzle, for half an hour   FALSE                     TRUE
 Drizzle, for sometime       FALSE                     TRUE
 Rain, non stop              TRUE                      FALSE
 Slight rain                 FALSE                     TRUE

Actual output

 TypeError: unhashable type: 'list'
 ----> 4     df['Heavy Rain Indicator'] = (df['Weather'].str.contains(heavy_rain_indicator))

I want the columns Heavy rain indicator to be TRUE when heavy rain indicators are present and light rain indicator to be TRUE when light rain indicators are present

lang-py