Use pivot
, then stack
df.pivot(*df.columns).fillna(0).stack().to_frame('values').reset_index()
Out[564]:
col1 col2 values
0 1 A 2.0
1 1 B 4.0
2 1 C 0.0
3 2 A 6.0
4 2 B 8.0
5 2 C 10.0
More Related Contents:
- Comparing two dataframes and getting the differences [duplicate]
- Pandas: How to easily share a sample dataframe using df.to_dict()?
- Pandas: Get Dummies
- Get the name of a pandas DataFrame
- Calculate weighted average using a pandas/dataframe
- Comparing previous row values in Pandas DataFrame
- What is the difference between join and merge in Pandas?
- Ambiguity in Pandas Dataframe / Numpy Array “axis” definition
- Counting unique values in a column in pandas dataframe like in Qlik?
- Pandas SettingWithCopyWarning [duplicate]
- flattening nested Json in pandas data frame
- subsetting a Python DataFrame
- How can I count the number of consecutive TRUEs in a DataFrame?
- Max and Min date in pandas groupby
- Pandas data precision [duplicate]
- Pandas rolling apply using multiple columns
- pd.read_html() imports a list rather than a dataframe
- pandas bar plot combined with line plot shows the time axis beginning at 1970
- how to test if a variable is pd.NaT?
- How to change the plot order of the categorical x-axis
- Plotting histograms from grouped data in a pandas DataFrame
- making matplotlib scatter plots from dataframes in Python’s pandas
- Pandas pivot warning about repeated entries on index
- Convert a pandas groupby object to list of dataframes
- How to annotate grouped bar plot with percent by hue/legend group
- Set value on an entire column of a pandas dataframe
- seaborn heatmap using pandas dataframe
- Sorted bar charts with pandas/matplotlib or seaborn
- UnicodeDecodeError when reading CSV file in Pandas
- how to understand closed and label arguments in pandas resample method?