Skip to content

Tag: pandas

pandas replace values in reference to a user input

I am stuck a little bit, hope you can help me, I want to replace a value in a pandas df according to a input Pandas df contains 3 string columns and the default value for category is always 1 Area Name Category Sales Tom 1 Finance Laura 1 Finance An 1 Ops Roger 1 I have a dict= {‘finance’:’2…

Python – How to clean time series data

I have a df which looks like this: I’m trying to create a new column called ‘First_Contract’: ‘First_Contract’ needs to take the third-last value of ‘Sep’ column, before ‘Sep’column reaches NaN. The subsequent values need to be filled with ‘Dec&#8217…

Pandas columns created function on Groupby sorted columns

I have a dataframe like below. What i am trying to do is calculate a column E1 and F1 with a sort and group by then return the entire data frame. The B1 column is incremental, but not necessarily by 1, but the sort on B1 will be if i only had one A1 value like my workflow is Which

list in dictionary get empty out when coming out of the loop

This is the code I wrote for web scraping purposes. I want to save all data in the dictionary and then save that data into a dataframe. Up to the last iteration, it saves the dictionary, but when coming out of the loop all lists (that are the values of my dictionary) are empty. How can one fix that? This

How to downcast numeric columns in Pandas?

How to optimize the data frame memory footprint and find the most optimal (minimal) data types dtypes for numeric columns. For example: Expected result: Answer You can use parameter downcast in to_numeric with selectig integers and floats columns by DataFrame.select_dtypes, it working from pandas 0.19+ like m…