From 19eb48cea2b41e0c7b05086457f3dd423fa1b11d Mon Sep 17 00:00:00 2001 From: rakesh kumar Date: Wed, 20 May 2020 18:27:25 +0530 Subject: [PATCH] Python pandas dataframe --- pandas/df_access_column.py | 15 +++++++++++++++ pandas/df_access_rows.py | 15 +++++++++++++++ pandas/df_creation1.py | 11 +++++++++++ pandas/df_creation2.py | 12 ++++++++++++ pandas/df_creation3.py | 4 ++++ pandas/df_creation4.py | 4 ++++ pandas/df_creation5.py | 15 +++++++++++++++ pandas/tempCodeRunnerFile.py | 15 +++------------ 8 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 pandas/df_access_column.py create mode 100644 pandas/df_access_rows.py create mode 100644 pandas/df_creation1.py create mode 100644 pandas/df_creation2.py create mode 100644 pandas/df_creation3.py create mode 100644 pandas/df_creation4.py create mode 100644 pandas/df_creation5.py diff --git a/pandas/df_access_column.py b/pandas/df_access_column.py new file mode 100644 index 0000000..b5703ba --- /dev/null +++ b/pandas/df_access_column.py @@ -0,0 +1,15 @@ +# create dataframe using list of Tuple +import pandas as pd +data = [ + (1101, 'rakesh', 56, 5656.56), + (1203, 'jatin jain', 56, 5666.56), + (1205, 'pushkar', 78, 5666.56), + (1206, 'arushi', 98, 4564.34), + (1208, 'mannat bhatia', 89, 4500), + (1234, 'unnati', 67, 3500.56), + (1245, 'Nikunj Tyagi', 68, 4500), + (5755, 'vishank', 89, 5000) +] +heading = ["admno", "name", "marks", "fees"] +df = pd.DataFrame(data, columns=heading) +print(df[['name','fees']] diff --git a/pandas/df_access_rows.py b/pandas/df_access_rows.py new file mode 100644 index 0000000..a615797 --- /dev/null +++ b/pandas/df_access_rows.py @@ -0,0 +1,15 @@ +# create dataframe using list of Tuple +import pandas as pd +data = [ + (1101, 'rakesh', 56, 5656.56), + (1203, 'jatin jain', 56, 5666.56), + (1205, 'pushkar', 78, 5666.56), + (1206, 'arushi', 98, 4564.34), + (1208, 'mannat bhatia', 89, 4500), + (1234, 'unnati', 67, 3500.56), + (1245, 'Nikunj Tyagi', 68, 4500), + (5755, 'vishank', 89, 5000) +] +heading = ["admno", "name", "marks", "fees"] +df = pd.DataFrame(data, columns=heading) +print(df[1]) \ No newline at end of file diff --git a/pandas/df_creation1.py b/pandas/df_creation1.py new file mode 100644 index 0000000..3d54a39 --- /dev/null +++ b/pandas/df_creation1.py @@ -0,0 +1,11 @@ +# create dataframe using Python Dictionary +import pandas as pd +df= pd.DataFrame( + { + 'admno' :[10,12,45,56,78,88], + 'name' :['rakesh','tarun','nikunj','arushi','pushkar','jatin'], + 'marks' :[56,67,78,99,67,56], + 'fees' :[345.67,676.45,677,456,7687,5656] + } +) +print(df) \ No newline at end of file diff --git a/pandas/df_creation2.py b/pandas/df_creation2.py new file mode 100644 index 0000000..853c5ac --- /dev/null +++ b/pandas/df_creation2.py @@ -0,0 +1,12 @@ +# create dataframe using list of Python Dictionary +import pandas as pd +df = pd.DataFrame( + [ + {'admno': 1101,'name': 'rakesh','marks' :56, 'fees': 5656.56}, + {'admno': 1203, 'name':'jatin jain','marks':56, 'fees': 5666.56}, + {'admno': 1205, 'name':'pushkar','marks':78, 'fees': 5666.56}, + {'admno': 1206, 'name':'arushi','marks':98, 'fees': 4564.34}, + {'admno': 1208, 'name':'mannat bhatia','marks':89, 'fees': 4500} + ] +) +print(df) diff --git a/pandas/df_creation3.py b/pandas/df_creation3.py new file mode 100644 index 0000000..3f363cf --- /dev/null +++ b/pandas/df_creation3.py @@ -0,0 +1,4 @@ +# create pandas dataframe using csv file +import pandas as pd +df = pd.read_csv('student.csv') +print(df) \ No newline at end of file diff --git a/pandas/df_creation4.py b/pandas/df_creation4.py new file mode 100644 index 0000000..2233f99 --- /dev/null +++ b/pandas/df_creation4.py @@ -0,0 +1,4 @@ +# create python pandas using Excel file +import pandas as pd +df = pd.read_excel("result.xls","result") +print(df) \ No newline at end of file diff --git a/pandas/df_creation5.py b/pandas/df_creation5.py new file mode 100644 index 0000000..5b2accd --- /dev/null +++ b/pandas/df_creation5.py @@ -0,0 +1,15 @@ +# create dataframe using list of Tuple +import pandas as pd +data = [ + (1101, 'rakesh', 56,5656.56), + (1203, 'jatin jain',56, 5666.56), + (1205,'pushkar',78,5666.56), + (1206,'arushi', 98, 4564.34), + (1208,'mannat bhatia', 89, 4500), + (1234,'unnati',67,3500.56), + (1245,'Nikunj Tyagi',68,4500), + (5755,'vishank',89,5000) +] +heading = ["admno","name","marks","fees"] +df = pd.DataFrame(data,columns=heading) +print(df) diff --git a/pandas/tempCodeRunnerFile.py b/pandas/tempCodeRunnerFile.py index e8a486f..2233f99 100644 --- a/pandas/tempCodeRunnerFile.py +++ b/pandas/tempCodeRunnerFile.py @@ -1,13 +1,4 @@ -# retirve values from pandas series using head() and tail() function - +# create python pandas using Excel file import pandas as pd -s= pd.Series(range(1,1000,5)) -#print top 5 entries of the series -print(s.head()) -#print top 2 entries of the series -print(s.head(2)) - -#print last 5 entries of the series -print(s.tail()) -# print last 2 entries of the series -print(s.tail(2)) \ No newline at end of file +df = pd.read_excel("result.xls","result") +print(df) \ No newline at end of file