I have a table with cities (the pandas.DataFrame object with a single 'city' column) table and the pandas.Series - cities object, which is the first column of this table ( cities = table['city'] ).
I need to sort the cities in such a way that only the words that satisfy this condition are left in it. In this case, I need to leave only cities in cities beginning with the letter 'ΠΌ' . I need something similar to the action described below, but only with the help of pandas, not lists:
lst = [word for word in cities if word[0] == 'ΠΌ'] How can I accomplish this? I tried it, but it gives me a KeyError: False
lst = table.loc[cities[0] == 'ΠΌ'] Although, if you need to leave only the fields with the specified value, it works:
lst= table.loc[cities != 'ΠΌΠ°Π³Π°Π΄Π°Π½'] How is it possible in the pandas.Series object to leave only the fields starting with a given letter?