<jupyter_start><jupyter_text>DataFrame - create, view, modify and sort<jupyter_code>import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import webbrowser as wb
site='https://en.wikipedia.org/wiki/NFL_win-loss_records'
wb.open(site)<jupyter_output><empty_output><jupyter_text>Creating a DF by pasting data from the clipboard<jupyter_code>nfl= pd.read_clipboard()
nfl<jupyter_output><empty_output><jupyter_text>Creating a new DF from a DF<jupyter_code>new_nfl=DataFrame(nfl,columns=['Team','Total Games','Stadium']) # creating a new dataframe from a df
new_nfl<jupyter_output><empty_output><jupyter_text>Creating a DF by converting a Dicitonary object<jupyter_code>data = {'City':['SF','LA','NYC'],'Population':[864816,3976000,8538000]}
data
citydf = DataFrame(data)
citydf<jupyter_output><empty_output><jupyter_text>Creating a DF by passing a ndarray, DatetimeIndex and Labeled columns<jupyter_code>dates = pd.date_range('20130101', periods=6)
df= DataFrame(np.random.randn(6,4),
             index=dates,
             columns=list('ABCD'))
df<jupyter_output><empty_output><jupyter_text>Viewing data  `.tail()` returns the bottom rows of the df. By default it returns 5 rows<jupyter_code>nfl.tail(2)<jupyter_output><empty_output><jupyter_text>Same thing with `.head()`. Except it returns the top rows<jupyter_code>nfl.head(2)<jupyter_output><empty_output><jupyter_text>`.columns` gives all the names of, you guessed it, columns.<jupyter_code>nfl.columns<jupyter_output><empty_output><jupyter_text>`.index` prints out the nature of the Index<jupyter_code>nfl.index
nfl.values<jupyter_output><empty_output><jupyter_text>`.describe()` shows us `count`, `mean`, `std`, `min`, `25%`, `50%`, `75%`(percentiles), `max`<jupyter_code>nfl.describe()<jupyter_output><empty_output><jupyter_text>`.T` transposes the dataframe object<jupyter_code>nfl.T<jupyter_output><empty_output><jupyter_text>Adding & Modifying columns   Adding one value to all rows of a column ```pythondf['new_column_name'] = "column_value"```<jupyter_code>nfl['Stadium']="Levi's Stadium"
nfl<jupyter_output><empty_output><jupyter_text>Adding a ndarray to rows of a column<jupyter_code>nfl['Stadium']=np.arange(1,6) 
nfl<jupyter_output><empty_output><jupyter_text>Adding Series to a row of columns in a DF<jupyter_code>stadiums=Series(["Levi's Stadium", "AT&T Stadium"], index=[4,0])
stadiums
nfl['Stadium']=stadiums 
nfl<jupyter_output><empty_output><jupyter_text>Deleting a column in a DF<jupyter_code>del nfl['Stadium']
nfl<jupyter_output><empty_output><jupyter_text>Sorting  Sorting by axis<jupyter_code>nfl.sort_index(axis=1, ascending=False)<jupyter_output><empty_output><jupyter_text>Sorting by values of column(s)<jupyter_code>nfl.sort_values(by='Won',ascending=False) # sorting by values in a row in a columnn
ser1= Series(np.random.randn(10))
ser1
ser1.sort_values()<jupyter_output><empty_output><jupyter_text>`.Rank()` Rank of the index-values in respect to the data-values<jupyter_code>ser1.rank()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.132406487917908, 'fraction_numerical': 0.016881827209533268, 'mean_word_length': 9.493055555555555, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 1, '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': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '292925', 'license': 'MIT', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1134, 'n_words': 209, 'path': 'pd/pd2 - DataFrame.ipynb', 'repo_name': 'subhamsarangi/Pdnp', 'size': '3021'}