How do I remove/omit the count column from the dataframe in Pandas?

Mike

This is probably very simple, but I've searched for hours and I can't find how to remove/omit column 1 (count column) in pandas?

Currently looks like:

    ID     Test1    Test2   Test3
1   236    data1    data2   data3   
2   323    data4    data5   data3
3   442    data6    data2   data4
4   543    data8    data2   data3
5   676    data1    data8   data4

Needs to look like:

ID     Test1    Test2   Test3
236    data1    data2   data3   
323    data4    data5   data3
442    data6    data2   data4
543    data8    data2   data3
676    data1    data8   data4

Code Snippet:

df = df[['ID','Test1','Test2','Test3']]
df.sort_values(['ID'], ascending=[True], inplace=True)
return render_template('index.html', data=df.to_html(index_names=False))

Thanks!

EdChum

If you want to use a specific column as your index then you just use set_index:

In [24]:
df.set_index('ID', inplace=True)
df

Out[24]:
     Test1  Test2  Test3
ID                      
236  data1  data2  data3
323  data4  data5  data3
442  data6  data2  data4
543  data8  data2  data3
676  data1  data8  data4

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I count the values from a pandas column which is a list of strings?

Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?

How do I get the row count of a pandas DataFrame?

How do I convert a pandas dataframe column of unique rows into separate column headings, count, and sum the adjacent row values?

How do I count the total number of words in a Pandas dataframe cell and add those to a new column?

In Pandas, how do I create a dataframe from a count of items in a column that are separated by commas?

How do I count the number of items with a specific column name from a Pandas df? (Python)

pandas - how do i get the difference from a dataframe on the same column

How do I count how often a column value changes in a pandas dataframe

How do I group by a column, and count values in separate columns (Pandas)

how do I get the count of rows in a appended/merged DataFrame in pandas?

How do I split data out from one column of a pandas dataframe into multiple columns of a new dataframe

How to update the count column of a pandas DataFrame from multiple DataFrames?

How do I count how often a column value changes in a pandas dataframe?

How do I insert a percentage column in a pandas dataframe?

How do I generate a new column subtracting the sorted one from the original in a pandas DataFrame?

How do I get all values from one position in a tuple in a pandas dataframe column?

How do I create a column in a pandas dataframe using values from two rows?

How do I drop rows with NaN in any column from a pandas DataFrame

How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

How can I count the number of floats or integers in a column of a Pandas dataframe?

How do I extract a column from a pandas dataframe in order to use it indepedently?

Pandas: How do I extract only the years from the age data in a column from my dataframe?

How do I group a pandas DataFrame using one column or another

How do I extract numbers from a dataframe column which follows a recurring pattern using pandas?

Pandas DataFrame: How do I create numerical values out of numerical values from another column?

How do I append to a Pandas DataFrame column?

How Do I Create New Column In Pandas Dataframe Using Two Columns Simultaneously From A Different Dataframe?

How do I prevent a numpy ndarray column from being converted to string when saving a Pandas DataFrame to csv?