Skip to content
Advertisement

Tag: pandas

Python: Datetime to season

I want to convert a date time series to season, for example for months 3, 4, 5 I want to replace them with 2 (spring); for months 6, 7, 8 I want to replace them with 3 (summer) etc. So, I have this series and this is the code I have been trying to use, but to no avail. and

Creating a dataframe from a dict where keys are tuples

I have the following dict, with keys as tuples: I’d like to create a dataframe with 3 columns: Col1, Col2 and Col3 which should look like this: I can’t figure out how to split the tuples other than parsing the dict pair by pair. Answer Construct a Series first, then resetting the index will give you a DataFrame: You can

Pythonic type hints with pandas?

Let’s take a simple function that takes a str and returns a dataframe: What is the recommended pythonic way of adding type hints to this function? If I ask python for the type of a DataFrame it returns pandas.core.frame.DataFrame. The following won’t work though, as it’ll tell me that pandas is not defined. Answer Why not just use pd.DataFrame? Result

Replacing values greater than a number in pandas dataframe

I have a large dataframe which looks as: I want to replace each element greater than 9 with 11. So, the desired output for above example is: Edit: My actual dataframe has about 20,000 rows and each row has list of size 2000. Is there a way to use numpy.minimum function for each row? I assume that it will be

Advertisement