Skip to content

Tag: pandas

How to combine two entry values in a column

In the dataset, the column “Erf Size” has entries like 1 733 and 1 539 etc. Note that the Dtype of this “Erf Size” column is object. I would like to join these 1 733 and 1 539 into 1733 and 1539 etc. original dataset expected output Answer I think you can fix this with pd.to_numeric. T…

Sort DataFrame based on part of its index

What I would like to achieve I have a DataFrame whose indices are “ID (int) + underscore (_) + name (str)”. I would like to sort the data based on the ID. What I tested I tried to use sort_index and failed. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_index.html…

Formula that calculates year real variation in pandas?

I have a dataframe with this info: I need to find a formula that calculates, for each of the 4 months of 2023, the real variation of column A against the same months of 2022. For example, in the case of 2023-04, the calculation is x = 140 (value of 2022-04) * 1,66 (accumulated inflation from 2022-04 to 2023-0…

Expand selected keys in a json pandas column

I have this sample dataset: And I want to ‘expand’ (or ‘explode’) each value in the json column, but only selecting some columns. This is the expected result: Firstly I tried using json_normalize and iterate over each row (even when the last row has no data), but I have to know before …