Search code examples
pythonpandasdataframedatatable

Delete colum of index 0 of dataframe pandas with python


I hope you can help me to sovle my problem, I am trying to do a programm where I can print out a pdf with a table that have 3 variable po#,name and description, when I used panda and I introduce PO# and convert this to html and then pdf, this happensIt shows everything but it has a row that contain a 0 with it and I can not dele this with drop(), how can I do to delete this?

It shows everything but it has a row that contain a 0 with it and I can not dele this with drop(), how can I do to delete this?

this is my code THIS IS THE CODE


Solution

  • Without the CSV file, it's tricky to estimate from where the zero may come from. However, from the pandas official documentation, the loc accepts the labels of the rows and only accept:

    • single labels (and accesses the whole raw);
    • a range of rows;
    • boolean array or Series (all True indexes will be selected);
    • a callable function that returns one of these;
    • a list of labels.

    That means the loc[] method doesn't accept the grid position of the cell listed with commas but instead a label to the column. In your case, when you type file.loc[0, "P)#"], Pandas treat 0 as a label of a row. Remember that loc[] treats all values as labels and never as indexes, therefore what I suggest you to do instead is to select the "PO#" row and assign its first item to the desired value:

    file.loc["PO#"][0] = po_number