Skip to content

Tag: pandas

Pandas: Date Format Changes from mmmyy to YYYY-MM-DD

I have a data frame column in mmmyy format and would like to change in yyyy-mm-dd format. Input : Output: tried: conv = lambda x: datetime.strptime(x, “%b %y”) Answer Sept doesn’t match the %b format as only 3 letters are valid. You could fix the string to keep only 3 letters: or .replace(r’…

Pandas cumsum with keys

I have two DataFrames (first, second): index_first value_1 value_2 0 100 1 1 200 2 2 300 3 index_second value_1 value_2 0 50 10 1 100 20 2 150 30 Next I concat the two DataFrames with keys: My goal is to calculate the cumulative sum of value_1 and value_2 in z considering the keys. So the final DataFrame shou…

Issue w/ pandas.index.get_loc() when match is found, TypeError: (“‘>’ not supported between instances of ‘NoneType’ and ‘str'”, ‘occurred at index 1’)

Below is the example to reproduce the error: The desired output should be a list or array with the values [3,NaN,4,3]. The NaN because it does not satisfy the criteria. I checked the pandas references and it says that for cases when you do not have an exact match you can change the “method” to &#8…