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…
Tag: pandas
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…
Scraping data from website that refreshes every 10 minutes in python
I am very new to web scraping and python in general. I am working on a project that requires me to scrape data from a website that refreshes/updates data every 10 minutes. I was able to scrape the data for the current 10 minutes but when the data refreshes the previous data is not valid anymore. I need help w…
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…
Finding string with multiple condition between two data frame in python
I have two dataframe df1 and df2. df1 has 4 columns. I want to add a new column Count in df2 in such a way that for every row in df2 if any string from Intersection or Roadway column exists in overall df1 data frame even once or more, the count column will have a value of 1. For example
How to fill the nan’s at the end of every column with 0’s in pandas python?
I want to forward fill my dataframe with a custom value – like 0. But pandas dosent allow to ffill with custom value. It only takes the last available value in every column and fills the nan values at the end with it. So was wondering if there was a better way to do this in python. Expected Output: Answ…
How to combine several rows into one based on a similar key in pandas dataframe?
Lets say I have a dataframe like this: Column1 Column2 Column 3 Column 4 Column 5 Column 6 Column 7 Platform_key amazonwebservicesaws asiapacificmumbai 38.33 nan nan nan nan amazonwebservicesaws_asiapacificmumbai amazonwebservicesaws asiapacificmumbai nan nan nan nan 1.83 amazonwebservicesaws_asiapacificmumba…
append or concat a row to a pandas df without collapsing multiindex
I’m trying to add a sum total to an already existing pandas dataframe. The problem is that when I do this my multiindices become just normal indices. How can I prevent that? neither this nor this works Maybe there is also an easier way to add a sum? Answer You’re not really creating a MultiIndex d…
Apply string in list according to beginning of the strings in a pandas dataframe column
Let’s take an example. I have a list of categories that are identified : The strings in that list can’t be a substring of another string in that list. And a dataframe : I would like to add a column Category to this dataframe. If the string in the column Items starts as a string in L_known_categori…
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…