主頁 > .NET開發 > 在查找資料框中從句子中洗掉單詞

在查找資料框中從句子中洗掉單詞

2021-12-08 16:33:37 .NET開發

我有兩個資料框,一個包含汽車評論,第二個包含汽車制造商和汽車模型。我想做的是使用汽車模型df_brand['name']來查找 Review 句子中的每個單詞df['Review']并洗掉匹配的單詞。我想洗掉所有包含汽車品牌的詞。

輸入資料df['Review']

Review
 The new Ford Focus came highly recommended to me when I was looking to buy my first new car  I researched its history and found that it received great reviews for comfort and safety during its European release  Test driving the car  I found it to be comfortable  well equipped and stylish  I have now driven the car for for 6 months and have put only 5000 miles on it  While I have been happy with the overall performance of the car  I have been sorely disappointed with the workmanship involved  Realizing that  new models  are notorious for having  manufacturing bugs  I felt somewhat reassured that these would have been worked out from 1998 1999 during the first European release  I was wrong  My car has been in the repair shop a total of five times for manufacturers defects including a flooded passenger compartment  repaired twice to date  faulty master clutch cylinder  misaligned striker plate on seat back latch  broken break switch and cruise control  While I really love my car  I would hesitate to recommend it to any but my worst enemies  Time will tell if the problems my Focus has had are unique or are related to intrinsic design flaws 
 We bought the Focus ZTS sedan because my wife needed an economical car to haul the grandkids around with  We traded in a  94 Explorer with a 5 speed just before the Firestone tire fiasco became public My wife loves driving the car  Although it is a bit small for me  6 1     290lbs  it is OK  The car handles great  and with the Zetec engine  it has adequate performance  although I wouldnt want any less   go   than its got Now for the problems   the main one of which is because I do my own oil changes  A particular sore point for me with most cars is that the manufacturers dont make it easy to change the oil and filter without creating a mess  This new Focus is particularly bad First  the owners manual indicates a Motocraft FL2005 filter  The car had an FL801 on it  which some ham fisted factory idiot had torqued to about a million foot pounds  I had to use some very large pliers and turn the filter almost 3 4 turn before it was loose enough to move by hand  Poor quality control The filter happens to be mounted in a horizontal position and is almost flush with the side of the engine  When I finally got it loose  oil ran down the side of the engine  onto the drive axle  onto the frame  down my arm  and all over the driveway  Very bad design  On other cars  I have been able to use a cut off soda bottle placed over the filter to catch the drips  On the Focus   it wont work The hood on this car is aluminum  It bends very easy   mine already has a dent in it   and I didnt have an accident  A minor problem is the power windows  They wont operate with the key in the accessory position  Tilt wheel also difficult to operate Bottom line   only 3 000 miles on this car  but its going to get traded off as soon as possible for a vehicle with a little more   substance   and which is easier to maintain  ive owned 9 Fords since 1986   still have 3  If all the newer Fords are made this way  the Focus may be the last Ford product I buy 
 Recently I had the need to rent a car  I picked the Ford Focus  I was amazed with this car  I liked it better than my own  more expensive 1999 Toyota Corolla LE  The steering wheel is not only height adjustable  but also telescopes  something you do not normally find on such a reasonably priced car  The drivers seat also adjusted forward and back and in height  nice feature for someone tall like myself  The front seats were roomy and comfortable and the back seat had I think the most leg room I HAVE EVER SEEN in a compact car The stereo sounded good considering it was stock  and the face of the radio has an upward tilt to it so that it is driver friendly  All the bells and whistles were located within easy reach and the air worked well In addition to having a roomy trunk  there are 60 40 split rear seats  Child safety seat anchors and shoulder harness seat belts for 5 passengers I rented the 4 door sedan  but there are 3 body styles  The 4 door sedan  4 door wagon and a sporty little hatch back  I have read the safety ratings for the hatch back and from what I recall it got 5 stars This car is definately on my list of cars to consider purchasing in the near future  you should take a look at it too 
  Cruising In My Big T  I have had my  91 Thunderbird for 4 years now  bought it way back in my freshman year and it has served me well throughout college  I am a horrible Northern driver and brutal on my vehicles  but this piece of Ford craftsmanship refuses to bail out on me  Its a rough and tumble vehicle that remains an incredible deal for the price  especially when bought used from a reputable dealer The Advantages  1 Seat Space These are big seats people  with the kind of legroom that only those pretentious you know whats in first class usually get their hands on  And that spaciousness isnt just about spoiling the people up front either  it extends to the back seat as well  which means that everyone feels just a little bit more comfortable and relaxed when you get to wherever you re going And not only are the seats big  but the generous amount of padding in each makes for an especially comfortable ride 2 Appearance ive gt to admit it to you  I just love the look of the Thunderbird  though it is an acquired taste to be sure  I can best describe the style as   Italian   sleek in a chunky way and available in colors  like burgundy  that make it look like a cross between a hit mobile and a hearse 3 Smooth Ride Riding in my Thunderbird has always seemed quite smooth to me  especially when you consider how low to the ground it is  Why so low  That kind of positioning allows the Thunderbird to provide the rider with great control  as your   feel   for the road is significantly enhanced In the same arena as the ride is the ease of use of the console  which for me equals smoothness and ease  The Thunderbirds radio and air console is incredibly well designed with everything within reach and intuitively organized  Seem trivial to you  Try changing the station at 75 miles an hour and see how important knob placement is 4 Trunk This is a important feature for me  as I seem to move every 3 6 months  The trunk on the Thunderbird is big enough for all of your luggage  not to mention the corpse of Vinnie The Chin from a rival family My Defense  I have read another review of this vehicle that criticizes the brake quality  and I have to vehemently disagree with it  I ride my brakes hard  and I have never had a lockup or other incident  The brakes do tend to squeek a bit  but the noise is no indication of a performance issue The Final Verdict  The bottom line is that the Thunderbird is a comfortable and well designed car at a reasonable price  As long as you like burgundy vehicles and live in an area thats at least 30  Italian  the Thunderbird is a great option 
 I arrived in the states from Australia at the end of March 1999 to stay there for a year and come home at the end of March 2000  I stayed with friends in South Carolina who is a Ford man as I have always owned GM or Chevs  they lent me a 1979 red corvette until I bought myself a car so after 3 months I did buy a 1985 Z28 Camaro  350  to fix up and use for the 9 months after looking at it I thought this was a bad idea so looked in the local paper and found a red 1991 V8 Thunderbird with 114 000 miles on it for  3000 After taking it for a test drive offered the lady  2800 and drove it home  it had a slight water leak from the water pump  so while replacing it I installed a set of under drive pulleys  which I could notice the power increase the first time I drove it  put a K amp N air cleaner in as well I had a friend come over from Australia so we drove from Greenville SC across to Sequin TX  did about 3000 miles in that trip  we took the long way  and had no trouble at all and got 27 MPG sitting on 80  MPH had a radar detector  it has a highway ratio in it 2 75 My brother came over from Australia so we went from Greenville SC down to Daytona Beach and back  then drove across America to California  which we did about 4600 miles trouble free  When we left Williams AZ the car was buried under snow as we had a cold snap and snow dig the snow away and turn the key starting the engine at once and never missing a beat The car came with the premium sound system  but the radio cassette was playing up so replaced it with a Pioneer radio CD I went to the wreckers and bought an electric motor seat assembly for the right hand side so when converting to RHD will have an electric adjustment  Also bought a sports instrument cluster and centre handbrake assy out of a super coupe These cars were never made for export or for Right Hand Drive  so have to get all the parts needed now for conversion I did 18 000 miles in 9 months without the car stopping or letting me down I gave the car 4 oil changes  added fuel octane booster with every tank of gas  it has the factory 15   alloy wheels with Michelin tyres  I found the car very easy to drive and steer  but did experience brake shudder  which appears to be a common problem due to thin brake rotors I added a rear spoiler and had the windows tinted  which makes the car look sporty  as in Australia the only 2 door cars are mainly Jap imports  so in the end I shipped the car back to Australia where I have to convert it over to Right Hand Drive for our road rules  this cars owes me  10 000 Australia  5200 US  landed back at my house in Australia  which when converted to RHD they sell from  35 000 to  40 000  18 000 to  21 000 US BEST CAR I HAVE EVER OWNED 
 This review is about  Ford Mustang 3 8L Coupe  with stick shift I test drove when I considered buying it  I say  considered  because I did not buy it and here is why Test Drive  The dealer talked too much during the test drive  They always try to do that to distract you  but I noticed the following things Styling  You can argue  but I think it could be better  The car looks bulky  the C pillars are thick  which increases  blind spots    I was afraid to run over somebody while backing up  the standard wheels look crude  The previous Mustang looked more balanced Engine  The 3 8L 193 hp engine does not seem all that powerful  even with stick  We went on the freeway onramp and I was disappointed  Strange  considering the 220  lb ft of torque rating at as low as 2800 rpm  European and Japanese manufacturers manage to extract more than 200 hp out of 3 0 liter engines Note  the A C was on during the test drive and was very efficient  It might eat some power  but not that much Transmission  The shifter has quite short travel  which is good  but the clutch does not provide any feedback   you cannot feel it engage by the pedal pressure  or the dealer talked too much  The clutch also engaged very high in the pedal travel  I drove some Eastern European cars for several years and never had complaints like this one  Or maybe im getting old and grumpy Suspension  The suspension is not only stiff  but creates a lot of unnecessary up and down motions  The car uses live axle in the rear  so I didnt expect much anyway Standard Equipment  The list of standard equipment looks good  It includes power windows  mirrors  locks and remote keyless entry  alloy  ugly  wheels  AM FM CD cassette player  A C  dual vanity mirrors  etc Interior  Interior  materials  fit and finish  looks cheap  I did not expect walnut for  16K  but Ford could have done better  As I said  the C pillars are wide  in coupe  and the interior room is smaller than Id like  The steering wheel tilts but does not telescope  which might be a problem for the tall people Insurance and Safety  Insurance rates are high  especially if you are a male younger than 25  The crash test results are not encouraging either   the overall rating is  Acceptable  with  Poor  death rate and  Marginal  injury rate Fuel Economy  I didnt get a chance to see the actual fuel consumption myself  but on paper its 19 MPG city   29 MPG highway  Not impressive for the car of this size with manual transmission Warranty and Reliability  Consumer Reports  magazine says that Mustang has poor reliability  Ford provides 36 000 mile   3 year warranty and 5 year corrosion warranty  Majority of other manufacturers offers 60 000 mile   5 year powertrain warranty  100 000 mile   10 year warranty for Hyundai Kia The last three  safety  fuel economy and reliability  also depend on the way you drive Pricing  The price was good  in theory  I know that you can get the car for less than  16K  at CarsDirect com  for example  but the particular dealership I went to wanted more than  17K and did not want to negotiate the price at all  Besides they were very pushy and rude  Needles to say  they did not earn my business  they didnt even try The dealer was constantly asking what monthly payment I can afford  Well  I can afford the payment I need to get better car  I walked  after which they called me several times asking how they can make me buy the car  today  I was unable to produce any kind of positive reply on this one I In car buying a lot depends on personal taste  If you like Mustangs styling and features and decide to buy it  it is a good deal  providing you with electric everything  remote keyless entry  radio CD cassette  V6 engine and alloy wheels for less than  16  If you want refinement  fit and finish  safety and reliability  get ready to pay more for something else I  

而review中要替換的lookup資料應該如下df_brand['name']

name
Alfa Romeo
Aston Martin
Audi
Bentley
BMW
Cadillac
Chery
Chevrolet
Chrysler
Citroen
Dacia
Daewoo
Daihatsu
DFM
Dodge
Ferrari
Fiat
Ford
Geely
Honda
Hyundai
Infiniti
Isuzu
Jaguar
Jeep
Kia
Lada
Lamborghini
Lancia
Land Rover
Maserati
Mazda
Mercedes
Mini
Mitsubishi
Nissan
Opel
Peugeot
Porsche
Proton
Renault
Rover
Saab
Seat
Skoda
Smart
SsangYong
Subaru
Suzuki
Tata
Tofa??
Toyota
Volkswagen
Volvo

所以到處都提到汽車名稱Ford或任何其他汽車品牌,我想洗掉這個名稱。

這是我嘗試使用的代碼示例:

query = df['clean_Review']
stopwords = df_brand['name'].tolist()
querywords = query

resultwords  = [word for word in querywords if word.lower() not in stopwords]
result = ' '.join(resultwords)

print(result)

uj5u.com熱心網友回復:

您的問題不夠濃縮,無法重現或查看所需的輸出,但您的基本方法很好。您可能會遇到拼寫錯誤的問題,在這種情況下,可以使用帶有閾值編輯距離來確定是否洗掉停用詞。這是我的代碼版本,看起來不錯

import re
stopwords = ["Ford", "Hyundai", "Toyota", "Volkswagen", "Volvo"]
tests = ["Something about a Ford doing some car stuff",
         "Hyundai is another car manufacturer",
         "Not everyone buys cars. Some people buy trucks from Toyota.",
         "Volkswagen is a German company.",
         "A lot of car brands like Toyota, Volkswagen, Volvo, do things"] 
stopwards_lower = [word.lower() for word in stopwords]
delimiters = " ", "...", ",", "."
for test in tests:
    querywords = list(filter(None, re.split('|'.join(map(re.escape, delimiters)), test)))
    resultwords  = [word for word in querywords if word.lower() not in stopwards_lower]
    result = ' '.join(resultwords)
    print(result)

注意:使用 re.findall 之類的東西(或使用像 spacy 或 gensim 這樣的 nlp 包)來洗掉所需的停用詞可能更容易在結果中找到所有停用詞。

uj5u.com熱心網友回復:

@Andrew Holmgren 做對了。如果您正在尋找一個簡單的答案并假設您clean_Review已經洗掉了除空格以外的所有內容來分隔單詞,您可以這樣做:

stopwords = ["ford", "hyundai", "toyota", "volkswagen", "volvo"]
tests = ["Something about a Ford doing some car stuff",
         "Hyundai is another car manufacturer",
         "Not everyone buys cars. Some people buy trucks from Toyota",
         "Volkswagen is a German company.",
         "A lot of car brands like Toyota Volkswagen Volvo do things"] 
querywords = pd.Series(tests)

resultwords  = [word for sentence in querywords for word in sentence.split(' ') if word.lower() not in stopwords]
result = ' '.join(resultwords)

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/376276.html

標籤:Python 数据框 抬头

上一篇:如何在另一列上創建具有條件的新列?

下一篇:R-如何使用聚合資料表創建圖形?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more