Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

I have string index in pandas DataFrame how can I select by startswith?

df = pd.DataFrame({'Nation':['Uw','A', 'Ur'],
                   'A':[2,3,5],
                   'Z':[4,5,6]})
df = df.set_index(['Nation'])
df[df.index.str.startswith('U')]
#If need select by level of MultiIndex use get_level_values:
df = df.set_index(['Nation', 'A'])
(
    df[df.index.get_level_values('Nation')
    .str.startswith('U')]
)


Comment

PREVIOUS NEXT
Code Example
Python :: bokeh xlabel rotate 
Python :: pandas filter rows by value 
Python :: how to declare a class in python 
Python :: iterate through a list 
Python :: plot data python 
Python :: python create file in current directory 
Python :: make a label using tkinter in python 
Python :: python range in intervals of 10 
Python :: python string to list new line 
Python :: install os conda 
Python :: Delete python text after 1 sec 
Python :: python list files in folder with wildcard 
Python :: gaussian filter 
Python :: count how much a number is in an array python 
Python :: Using a list with index and column names to Convert List to Dataframe 
Python :: Highlight Active Links in Django Website 
Python :: py2exe no console 
Python :: matplotlib larger chart 
Python :: python autoclicker 
Python :: Creating and writing to a new file 
Python :: python convert list of lists to array 
Python :: python get numbers after decimal point 
Python :: python type hinting pandas dataframe 
Python :: check for string in list py 
Python :: savefig matplotlib python 
Python :: pandas read csv without scientific notation 
Python :: django model remove duplicates 
Python :: cronometer python 
Python :: python bufferedreader 
Python :: discord.py setup_hook 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =