Advance Operations On Dataframes: Create A Dataframe With Following Values
Advance Operations On Dataframes: Create A Dataframe With Following Values
ASSIGNMENTS
Q.1 Create a dataframe with following values
Indicator Country Year Value
1 India 2005 6
2 India 2005 13
3 India 2005 10
4 India 2005 11
5 India 2005 5
1 India 2006 3
2 India 2006 2
3 India 2006 7
4 India 2006 3
5 India 2006 6
Ans.
print (df.pivot_table(index='Position', columns='City', values='Name', aggfunc=',
'.join, fill_value='-')
.reset_index()
.rename_axis(None, axis=1))
import pandas as pd
table = {
"Name": ["anil", "vishal","manish","mohak"],
"Age": [12,34,22,14],
}
df = pd.DataFrame(table)
print(df)
print (df.pivot_table(index="Name",columns="Name",values="Age"))