Skip to content
Advertisement

Tag: dataframe

Create DF Columns Based on Second DDF

I have 2 dataframes with different columns: I would like to add the missing columns for the 2 dataframes – so each one will have each own columns + the other DFs columns (without column “number”). And the new columns will have initial number for our choice (let’s say 0). So the final output: What’s the best way to achieve

Transpose dataframe based on column list

I have a dataframe in the following structure: I would like to transpose – create columns from the names in cNames. But I can’t manage to achieve this with transpose because I want a column for each value in the list. The needed output: How can I achieve this result? Thanks! The code to create the DF: Answer One option

Repeat pattern using python regex

Well, I’m cleaning a dataset, using Pandas. I have a column called “Country”, where different rows could have numbers or other information into parenthesis and I have to remove them, for example: Australia1, PerĂº (country), 3Costa Rica, etc. To do this, I’m getting the column and I make a mapping over it. But I have a problem with this regex,

Filter Pandas MultiIndex over all First Levels Columns

Trying to find a way of efficiently filtering all entries under both top level columns based on a filter defined for only one of the top level columns. Best explained with the example below and desired output. Example DataFrame Create filter for multiindex dataframe Desired output: Answer You can reshape for simplify solution by reshape for DataFrame by DataFrame.stack with

Advertisement