Reputation: 906
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
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