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!
We can exclude one column from the pandas dataframe by using the loc function. This function removes the column based on the location.
You can also use DataFrame. drop() method to delete the last n columns. Use axis=1 to specify the columns and inplace=True to apply the change on the existing DataFrame.
You can use the following syntax to exclude columns in a pandas DataFrame: #exclude column1 df. loc[:, df. columns!='
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With