Skip to content

Tag: python

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…

Joining two CSV files with common column in Python without Pandas

I wanted to inquire on how I could merge 2 csv files so that I can generate queries. Note that I am not allowed to use the “pandas” library. As an example I have these 2 csv: data.csv: enti.csv: And what I’m looking for is to be able to join them through cod_enti and thus be able to evaluate…

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…

Learning Python: Printing Variable Key Arguments

I’m trying to write a program that can take and print a variable number of arguments. The code is below. My code works, however, the format of the output is not what I am trying to achieve. Can someone help me work around the output? Desired output: My output: Answer I apparently went too far I guess? T…