👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I am parsing data from an Excel file that has extra white space in some of the column headings.
When I check the columns of the resulting dataframe, with df.columns
, I see:
Index(["Year", "Month ", "Value"])
^
# Note the unwanted trailing space on "Month "
Consequently, I can"t do:
df["Month"]
Because it will tell me the column is not found, as I asked for "Month", not "Month ".
My question, then, is how can I strip out the unwanted white space from the column headings?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from How can I strip the whitespace from Pandas DataFrame headers?, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano How can I strip the whitespace from Pandas DataFrame headers?
- Deutsch How can I strip the whitespace from Pandas DataFrame headers?
- Français How can I strip the whitespace from Pandas DataFrame headers?
- Español How can I strip the whitespace from Pandas DataFrame headers?
- Türk How can I strip the whitespace from Pandas DataFrame headers?
- Русский How can I strip the whitespace from Pandas DataFrame headers?
- Português How can I strip the whitespace from Pandas DataFrame headers?
- Polski How can I strip the whitespace from Pandas DataFrame headers?
- Nederlandse How can I strip the whitespace from Pandas DataFrame headers?
- 中文 How can I strip the whitespace from Pandas DataFrame headers?
- 한국어 How can I strip the whitespace from Pandas DataFrame headers?
- 日本語 How can I strip the whitespace from Pandas DataFrame headers?
- हिन्दी How can I strip the whitespace from Pandas DataFrame headers?
Rome | 2023-02-07
Simply put and clear. Thank you for sharing. How can I strip the whitespace from Pandas DataFrame headers? and other issues with re Python module was always my weak point 😁. Will get back tomorrow with feedback
San Francisco | 2023-02-07
Maybe there are another answers? What How can I strip the whitespace from Pandas DataFrame headers? exactly means?. Will use it in my bachelor thesis
Boston | 2023-02-07
re Python module is always a bit confusing 😭 How can I strip the whitespace from Pandas DataFrame headers? is not the only problem I encountered. Checked yesterday, it works!