简体   繁体   English

如何清理这个 dataframe。我想使用 python 从表中删除“\n”而不影响表

[英]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.

相关问题 I want to count the elements of a python list that is within a dataframe, and for the output to be a column in the dataframe. 我怎么做? - I want to count the elements of a python list that is within a dataframe, and for the output to be a column in the dataframe. How do I do that? 我想从一个数据框中选择其值存在/不存在于另一个数据框中的所有记录。 如何使用 pyspark 数据框执行此操作? - I want to select all records from one dataframe where its value exists/not exists in another dataframe. How to do this using pyspark dataframes? 熊猫数据框索引在索引数据框的子集时引起问题。 如何删除索引,或防止发生错误? - Pandas dataframe index causing problems when indexing subset of dataframe. How do I remove the indexes, or prevent the error from occurring? 如何从beautifulsoup(Python)中的表中删除列 - How do I remove a column from a table in beautifulsoup (Python) 我想从 fasta 文件中解析序列和序列 ID,并将它们分配给 Dataframe。 我正在使用 biopython 中的 SeqIO 库 - I want to parse Sequences and sequence Ids from a fasta file and assign them to Dataframe. I am using SeqIO library from biopython 如何将 Pandas DataFrame 绘制为没有索引列的表? - How do I plot a pandas DataFrame as a table without the index column? 在数据框上使用.sort_values之后。 我想访问它在排序时提供的索引 - After using .sort_values on a dataframe. I want to access the index that it provides while sorted 如何从我的python字典中删除\\ n? - How do I remove \n from my python dictionary? 我的熊猫数据框中缺少数据。 我如何告诉python不要在新的数据框中包含它? - I have missing data in my pandas dataframe. How can I tell python not to include it in a new dataframe? 如何使用python从数据库中提取表元数据 - How do I extract table metadata from a database using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM