Skip to content

Tag: pandas

‘str’ object has no attribute ‘to_csv’

I’m trying to save some data that I collected on a csv file. And for that I’m using the following code, but I’m getting the error: ‘str’ object has no attribute ‘to_csv’ I am using this line df = pd.to_numeric(df, errors=’ignore’) to change Nonetype to num…

Lambda function apply on dataframe DOES not contain str

I’m trying to add a condition .apply with a lambda function that pickups up a keyword but ignores values if they contain a specific word “total.” My dataframe: Here’s my code: current col output: Desired col output: Question What am I doing wrong? I have tried the ~ to make it a NOT bu…

Check if value of dataframe is existing in list

I am trying to split a pandas Dataframe into two, based on the value in the column “country”. If the value exists in the following list (EU-COUNTRY-CODES), the row should be added to a dataframe called “EU”, if it does not exist in the list I want to add the row to another dataframe. I…

Removing index from pandas data frame on print

I’m really struggling to get this to print the way I want to. I’ve read through the documentation on removing index, but it seems like it still shows up. Here is my code: The text file isn’t anything special, looks like this: The output of this looks like this: How do I get rid of those rand…