<jupyter_start><jupyter_text>Reshaping  Melt<jupyter_code>df1 = pd.melt(df, id_vars=['day'])
df1<jupyter_output><empty_output><jupyter_text>Filter on city<jupyter_code>df1[df1['variable']=='chennai']<jupyter_output><empty_output><jupyter_text>Changing variable and value<jupyter_code>melted = pd.melt(df, id_vars=['day'], var_name='city', value_name='temperature')
melted
df_unmelted = melted.pivot(index='day', columns='city')
df_unmelted<jupyter_output><empty_output><jupyter_text>Stacking<jupyter_code>df2 = pd.read_excel('https://github.com/dayanandv/Data-Science/raw/main/dataset/stocks.xlsx', header=[0,1])
df2
df2.stack()
df2.stack(level=0)
df2_stacked=df2.stack()
df2_stacked
df2_stacked.unstack()<jupyter_output><empty_output><jupyter_text>Pivot  Basics<jupyter_code>df3 = pd.read_csv('https://raw.githubusercontent.com/dayanandv/Data-Science/main/dataset/weather_pivot.csv')
df3
df3.pivot(index='city', columns='date')
df3.pivot(index='city',columns='date',values="humidity")<jupyter_output><empty_output><jupyter_text>Table<jupyter_code>df3.pivot_table(index='city', columns='date', aggfunc='sum')<jupyter_output><empty_output><jupyter_text>Margins<jupyter_code>import numpy as np
df3.pivot_table(index='city', columns='date', margins=True, aggfunc=np.sum) # sum, diff<jupyter_output><empty_output><jupyter_text>Grouper<jupyter_code>df3
df3['date']=pd.to_datetime(df3['date'])
df3.pivot_table(index=pd.Grouper(freq='M',key='date'),columns='city')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1714862138533961, 'fraction_numerical': 0.016812373907195696, 'mean_word_length': 15.0, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '289091', 'license': 'MIT', 'n_tokens_mistral': 633, 'n_tokens_neox': 619, 'n_words': 46, 'path': 'Reshaping,_Pivoting.ipynb', 'repo_name': 'M2kishore/Data-Science-1', 'size': '1487'}