Skip to content

Tag: pandas

Using result_type with pandas apply function

I want to use apply on a pandas.DataFrame that I created, and return for each row a list of values, where each value is a column in itself. I wrote the following code: When I add result_type=’expand’ in order to change the returned array into separate columns I get the following error: However if …

How to move a column in a pandas dataframe

I want to take a column indexed ‘length’ and make it my second column. It currently exists as the 5th column. I have tried: I see the following error: TypeError: must be str, not list I’m not sure how to interpret this error because it actually should be a list, right? Also, is there a gener…

Convert dataframe to a rec array (and objects to strings)

I have a pandas dataframe with a mix of datatypes (dtypes) that I wish to convert to a numpy structured array (or record array, basically the same thing in this case). For purely numeric dataframes, this is easy to do with the to_records() method. I also need the dtypes of pandas columns to be converted to st…

Delete rows that do not contain specific text

I have a tabular file that looks like this: I’m trying to create a script to go through and delete the entire row if column 2 (‘KEGG_KOs’) does not begin with ‘K0’. I’m trying to create an output of: Previous responses have referred people to pandas DataFrame but I’ve…