[英]How do I clean this dataframe. I want to remove "\n" from the table using python without affecting the table
I have this dataframe parsed from a web page using web-scraping.我使用网络抓取从 web 页面解析了这个 dataframe。 Libraries used are, bs4(BeautifulSoup), pandas, requests and urllib.
使用的库是 bs4(BeautifulSoup)、pandas、requests 和 urllib。 The table has to be downloaded in csv for data visualisation in tableau afterwards.
表格需要在csv下载,之后在tableau中进行数据可视化。 So without affecting any of the rows and columns, I want to remove "\n" from the dataframe. Any help will be appreciat enter image description here ed.
因此,在不影响任何行和列的情况下,我想从 dataframe 中删除“\n”。我们将不胜感激,请在此处输入图片描述。
You could do something like this:你可以这样做:
rank_details["Pos"] = Pos.text.strip('\n')
I think your question is answered within this question .我认为您的问题已在这个问题中得到解答。
More precisely,更确切地说,
dataFrame.replace('\n', '', regex=True)
should do it for you.应该为你做。 Please note that after this, you may also need to strip the strings from leading and trailing whitespaces , and also to convert some of the columns (seemingly
Pos
should be an integer), with the astype method .请注意,在此之后,您可能还需要使用astype 方法从字符串的前导和尾随空格中去除字符串,并且还需要转换一些列(貌似
Pos
应该是一个整数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.