Add source example files
This commit is contained in:
12
source/pandas/01-pandas-actions/01-dataframe-pivot.py
Normal file
12
source/pandas/01-pandas-actions/01-dataframe-pivot.py
Normal file
@ -0,0 +1,12 @@
|
||||
import pandas as pd
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.DataFrame({
|
||||
'country': ['fra', 'fra', 'fra', 'fra', 'bel', 'bel', 'bel', "bel"],
|
||||
'district': ['north', 'east', 'west', 'south', 'north', 'east', 'west', 'south'],
|
||||
'population': [10_000, 30_000, 50_000, 70_000, 20_000, 40_000, 60_000, 80_000],
|
||||
'extra': ['h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']
|
||||
})
|
||||
df2 = df.pivot_table(values=["population"], index="district", columns="country", aggfunc="count")
|
||||
print(df2.to_string())
|
||||
print(df2.columns)
|
Reference in New Issue
Block a user