steff
steff

Reputation: 906

Remove digits from pandas df column index

Can someone please point me towards the best way to remove the numbers from this df.columns. The df:

            1. open 2. high 3. low     4. close 5. volume
date                    
2000-01-03  1469.25 1478.00 1438.3600   1455.22 9.318000e+08
2000-01-04  1455.22 1455.22 1397.4301   1399.42 1.009000e+09

desired output:

            open    high    low       close     volume
date                    
2000-01-03  1469.25 1478.00 1438.3600 1455.22   9.318000e+08
2000-01-04  1455.22 1455.22 1397.4301 1399.42   1.009000e+09

.split('.')[1].strip() works but doesn't seem so elegant.

Upvotes: 0

Views: 663

Answers (1)

cs95
cs95

Reputation: 402263

Use Index.str.extract to extract the words out:

df.columns = df.columns.str.extract(r'([a-zA-Z]+)', expand=False)

Upvotes: 1

Related Questions