<jupyter_start><jupyter_text>DataFrame---- 2 Dimensional : data is aligned in a tabular fashion in rows and columns.- Potentially columns are of different types- Size – Mutable- Labeled axes (rows and columns)- Can Perform Arithmetic operations on rows and columns DataFrame Constructor ```pandas.DataFrame( data, index, columns, dtype, copy)```  where - data : data takes various forms like ndarray, series, map, lists, dict, constants and also another DataFrame- index : For the row labels, the Index to be used for the resulting frame is Optional. Default np.arange(n) if no index is passed.- columns : For column labels, the optional default syntax is - np.arange(n). This is only true if no index is passed.- dtype : Data type of each column.- copy : used for copying of data, default is False. Create an Empty DataFrame<jupyter_code>import pandas as pd
df = pd.DataFrame()
print(df)<jupyter_output>Empty DataFrame
Columns: []
Index: []<jupyter_text>Create a DataFrame from Lists<jupyter_code>data = [1,2,3,4,5]
dfl = pd.DataFrame(data)
print(dfl)
data = [['Falano0',21],['Falano1',22],['Falano3',25]]
dfl1 = pd.DataFrame(data,columns=['Name','Age'])
print(dfl1)<jupyter_output>Name  Age
0  Falano0   21
1  Falano1   22
2  Falano3   25<jupyter_text>Create a DataFrame from Dictionary<jupyter_code>data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
dfd = pd.DataFrame(data)
print(dfd)
data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
dfd1 = pd.DataFrame(data, index=['first', 'second'])
print(dfd1)
#With two column indices, values same as dictionary keys
df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b'])
print(df1)<jupyter_output>a   b
first   1   2
second  5  10<jupyter_text>Create a DataFrame from Series<jupyter_code>d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']),
   'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])}
dfs = pd.DataFrame(d)
print(dfs)<jupyter_output>one  two
a  1.0    1
b  2.0    2
c  3.0    3
d  NaN    4<jupyter_text>Column Selection---<jupyter_code>dfs['two']
#Add a column
dfs['three']=pd.Series([10,20,30],index=['a','b','c'],dtype=int)

print(dfs)

#remove a column
dfs.pop('three')
del dfs['three']<jupyter_output><empty_output><jupyter_text>Row Selection, Addition, and Deletion Selection by location<jupyter_code>print(dfs.loc['b'])
#The result is a series with labels as column names of the DataFrame. 
#And, the Name of the series is the label with which it is retrieved.<jupyter_output>one    2.0
two    2.0
Name: b, dtype: float64<jupyter_text>Selection by integer location<jupyter_code>print(dfs)
print(dfs.iloc[2])
#slicing
print(dfs[:2])<jupyter_output>one  two
a  1.0    1
b  2.0    2<jupyter_text>Addition of Rows<jupyter_code>dfr = pd.DataFrame([[5, 6], [7, 8]], columns = ['a','b'])

dfs = dfs.append(dfr)
print(dfs)<jupyter_output>one  two    a    b
a  1.0  1.0  NaN  NaN
b  2.0  2.0  NaN  NaN
c  3.0  3.0  NaN  NaN
d  NaN  4.0  NaN  NaN
0  NaN  NaN  5.0  6.0
1  NaN  NaN  7.0  8.0<jupyter_text>Drop rows<jupyter_code>dfs.drop(0)
dfs.drop?
dfs<jupyter_output><empty_output><jupyter_text>Import CSV In pandas---```pandas.read_csv```<jupyter_code>pd.read_csv?
covid_cases = pd.read_csv("owid-covid-data.csv")
print(type(covid_cases))
# covid_cases.loc?
covid_cases.head(20)
#  covid_cases.tail(5)
# covid_cases.loc[:2,"location"]<jupyter_output><class 'pandas.core.frame.DataFrame'><jupyter_text>SQL Select in Pandas<jupyter_code># select iso_code, continent, location from tables where rownum <= 5
covid_cases[['iso_code','continent', 'location']].head(5)
# select iso_code, continent, location from tables where location="International" and rownum <= 5
# covid_cases["location"]=="International"
# covid_cases[covid_cases["location"]=="International"]
covid_cases[covid_cases["location"]=="International"][['iso_code','continent', 'location']].head(5)<jupyter_output><empty_output><jupyter_text>Group By<jupyter_code>#select location, count(*) from table group by location
covid_cases.groupby('location').size()
covid_cases.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15285996055226825, 'fraction_numerical': 0.03106508875739645, 'mean_word_length': 5.564724919093851, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 42, 'https://': 0, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '135440', 'license': 'MIT', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1554, 'n_words': 408, 'path': 'Basics/Pandas - DataFrame.ipynb', 'repo_name': 'suraj-shakya/learning_python', 'size': '4056'}