我是Python的新手,每天都在学习。我想在python数据帧上将所有价格值从字符串“ 3K”转换为“ 3000”。无法继续。请帮助
我自己学习Python,在互联网上阅读很多,观看了很多youtube视频教程。这只是我无法完成的教程。
create_shape(8) ->
[ 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0,
0, 1, 1, 1, 0, 0,
0, 1, 1, 1, 1, 0,
0, 1, 1, 1, 1, 0 ]
import pandas as pd
import numpy as np
import re
def regex_filter(val):
if val:
#new_values = ' '
mo = re.search('\d+[kK]',val)
if mo:
print("The length of mo is ",mo)
new_values = str(mo) + "000"
print("The New value is ",new_values)
return True
else:
return False
else:
return False
if __name__ == "__main__":
df = pd.read_csv('ProductID_price.csv', encoding='utf8')
df_filtered = df[df['price'].apply(regex_filter)]