Cheap VPS host selection
Provide server host evaluation information

Method of deleting specific columns of dataframe in python

To delete a specific column of DataFrame in Python, you can use drop() Function. Here's how to use drop() The function deletes the sample code of a specific column in the DataFrame:

 import pandas as pd #Create a sample DataFrame data = { 'A' : [ one , two , three ], 'B' : [ four , five , six ], 'C' : [ seven , eight , nine ]} df = pd.DataFrame(data) #Print the original DataFrame
 print ( Original DataFrame: ) print (df) #Delete specific columns columns_to_drop = [ 'B' , 'C' ] df = df.drop(columns=columns_to_drop) #DataFrame after printing
 print ( NDataFrame after deleting a specific column: ) print (df)

The output will be:

 Original DataFrame: A  B  C zero one four seven one two five eight two three six nine DataFrame after deleting a specific column: A 0  1 1  2 2  3

In the above example, we first created a df DataFrame object, and then use the drop() The function deletes the specified columns ('B 'and' C '). Finally, we printed the DataFrame after deleting a specific column.

Do not reprint without permission: Cheap VPS evaluation » Method of deleting specific columns of dataframe in python