I have a pandas dataframe with +1000 columns. I would like to extract only the first 4 digits from all the headers.
Example of the original datafr:
| Q001-XYZ | Q002-XYZ |
|---|---|
| First | row |
| Second | row |
I would like to get:
| Q001 | Q002 |
|---|---|
| First | row |
| Second | row |
I tried df.head() = df.head().str[:4] but I get the error SyntaxError: can't assign to function call
Any suggestion?