[英]Iterating through dataframe and extract special characters
school_earning_premium_hourly dips_cert_earning_premium_weekly
5.785123966942149\B 110.7438016528926\I
I have multiple columns (2 of them are above) in my dataframe. 我的数据框中有多个列(上面有2列)。 I need a way to iterate through all of the columns and extract the unwanted characters.
我需要一种遍历所有列并提取不需要的字符的方法。
If i were to clean each column individually, I would use 如果我要分别清洁每一列,我会使用
data['school_earning_premium_hourly'] =
data.school_earning_premium_hourly.str.replace(
'[\\|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z]','')
But now I need to find a way to iterate over every single column(I have 103) and remove the characters as well as change the objects/strings to floats in order to plot the data. 但是现在我需要找到一种方法来遍历每一列(我有103个)并删除字符以及将对象/字符串更改为浮点数以绘制数据。
You can use the column names to loop through them all and do what you described: 您可以使用列名遍历所有列并执行您描述的操作:
for i in range(len(data.columns)):
col = data.columns[i]
data[col] = data[col].str.replace('[\|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z]','')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.