如何从数据框中选择一个特定的字符串?

时间:2019-05-30 03:25:25

标签: python csv dataframe

这是我的数据框:

RefactoringType RefactoringDetail
Pull Up Attribute   "Pull Up Attribute  protected steps : int from class blokusgame.mi.android.hazi.blokus.GameLogic.PlayerAlgorithm to class blokusgame.mi.android.hazi.blokus.GameLogic.Player"
Pull Up Attribute   "Pull Up Attribute  protected steps : int from class blokusgame.mi.android.hazi.blokus.GameLogic.PlayerAlgorithm to class blokusgame.mi.android.hazi.blokus.GameLogic.Player"
Pull Up Attribute   "Pull Up Attribute  protected steps : int from class blokusgame.mi.android.hazi.blokus.GameLogic.PlayerAlgorithm to class blokusgame.mi.android.hazi.blokus.GameLogic.Player"
Extract Method  "Extract Method private getBestMove(moves ArrayList<Move>) : 
Move extracted from public nextStep() : void in class blokusgame.mi.android.hazi.blokus.GameLogic.PlayerAlgorithm
Extract Method  "Extract Method private getNLongMoves(n int) : ArrayList<Move> extracted from private getAllPossibleMoves() : ArrayList<Move> in class blokusgame.mi.android.hazi.blokus.GameLogic.PlayerAlgorithm"
Extract Method  "Extract Method public getPoints() : ArrayList<Point> extracted from public equals(b Object) : boolean in class blokusgame.mi.android.hazi.blokus.GameLogic.Block"
Extract Method  "Extract Method public getMin() : Point extracted from public getDimensions() : Point in class blokusgame.mi.android.hazi.blokus.GameLogic.Block"
Extract Method  "Extract Method public getMax() : Point extracted from public getDimensions() : Point in class blokusgame.mi.android.hazi.blokus.GameLogic.Block"
Extract Method  "Extract Method public normalize() : Block extracted from public equals(b Object) : boolean in class blokusgame.mi.android.hazi.blokus.GameLogic.Block"
Extract Method  "Extract Method package setPlayer(player Player) : void extracted from protected onCreate(savedInstanceState Bundle) : void in class blokusgame.mi.android.hazi.blokus.MainActivity"
Extract Method  "Extract Method public isPlaceable(block Block, pt Point) : boolean extracted from public isPlaceable(block Block, corners ArrayList<Point>, pt Point) : boolean in class blokusgame.mi.android.hazi.blokus.GameLogic.Map"

我需要提取第一个String“ class”之后的部分。我使用了这段代码

import pandas as pd
df = pd.read_csv('result_refactorings.csv', sep=';')
refactoring_details = df['RefactoringDetail']
print(refactoring_details)
a=refactoring_details.to_frame(name=refactoring_details)
a.RefactoringDetail.str.extract(r'class ([^ ]*)') 

它没有返回包含NAN的所有行(从12行开始)的所有数据。我找不到问题 结果是:

0   blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
1   blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
2   blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
3   blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
4   blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
5   blokusgame.mi.android.hazi.blokus.GameLogic.Block
6   blokusgame.mi.android.hazi.blokus.GameLogic.Block
7   blokusgame.mi.android.hazi.blokus.GameLogic.Block
8   blokusgame.mi.android.hazi.blokus.GameLogic.Block
9   blokusgame.mi.android.hazi.blokus.MainActivity
10  blokusgame.mi.android.hazi.blokus.GameLogic.Map
11  blokusgame.mi.android.hazi.blokus.GameLogic.Pl...
12  NaN
13  NaN

PS:在某些行中有两个类词,我需要在第一类之后的数据,然后将结果放入一个csv文件中

感谢帮助

0 个答案:

没有答案