Reputation: 135
This is my pandas Dataframe:
file,class,type,cbo,wmc,dit,rfc,lcom,totalMethods,staticMethods,publicMethods,privateMethods,protectedMethods,defaultMethods,abstractMethods,finalMethods,synchronizedMethods,totalFields,staticFields,publicFields,privateFields,protectedFields,defaultFields,finalFields,synchronizedFields,nosi,loc,returnQty,loopQty,comparisonsQty,tryCatchQty,parenthesizedExpsQty,stringLiteralsQty,numbersQty,assignmentsQty,mathOperationsQty,variablesQty,maxNestedBlocks,anonymousClassesQty,subClassesQty,lambdasQty,uniqueWordsQty
C:\BlokusDuo-master\app\src\main\java\blokusgame\mi\android\hazi\blokus\GameLogic\Block.java,blokusgame.mi.android.hazi.blokus.GameLogic.Block,class,2,40,1,16,14,17,0,17,0,0,0,0,0,0,4,0,0,4,0,0,0,0,0,159,18,9,0,0,5,4,45,50,8,8,28,2,0,0,0,61
C:\BlokusDuo-master\app\src\main\java\blokusgame\mi\android\hazi\blokus\GameLogic\BlockFactory.java,blokusgame.mi.android.hazi.blokus.GameLogic.BlockFactory,class,3,22,1,23,231,22,22,1,21,0,0,0,0,0,0,0,0,0,0,0,0,0,21,224,22,0,0,0,0,0,199,43,0,0,43,0,0,0,0,33
I need to delete the column file and type. I used this code.
Import pandas as pd
import csv
df=pd.read_csv('class.csv', sep=',')
df=drop(['file','type'])
It return for me this
class cbo wmc dit rfc lcom totalMethods staticMethods publicMethods privateMethods protectedMethods defaultMethods abstractMethods finalMethods synchronizedMethods totalFields staticFields publicFields privateFields protectedFields defaultFields finalFields synchronizedFields nosi loc returnQty loopQty comparisonsQty tryCatchQty parenthesizedExpsQty stringLiteralsQty numbersQty assignmentsQty mathOperationsQty variablesQty maxNestedBlocks anonymousClassesQty subClassesQty lambdasQty uniqueWordsQty
C:\BlokusDuo-master\app\src\main\java\blokusgame\mi\android\hazi\blokus\GameLogic\Block.java class 40 1 16 14 17 0 17 0 0 0 0 0 0 4 0 0 4 0 0 0 0 0 159 18 9 0 0 5 4 45 50 8 8 28 2 0 0 0 61
C:\BlokusDuo-master\app\src\main\java\blokusgame\mi\android\hazi\blokus\GameLogic\BlockFactory.java class 22 1 23 231 22 22 1 21 0 0 0 0 0 0 0 0 0 0 0 0 0 21 224 22 0 0 0 0 0 199 43 0 0 43 0 0 0 0 33
It delete just file and type from the head but their values still. I also used del df['column_name']!
Any help please!
Upvotes: 1
Views: 165
Reputation: 835
I have added one line into your code to get the desired solution.
df=pd.read_csv('class.csv', sep=',')
df.drop(['file','type'], axis=1, inplace=True)
# axis=1 for column AND inplace=True will make changes in df.
df
I hope it may help you.
Upvotes: 0
Reputation: 789
You can skip that column using usecols
Import pandas as pd
import csv
df = pd.read_csv(
"class.csv",
usecols = lambda column : column not in ["class","type"],
index=False, sep=","
)
Upvotes: 2