Skip to content

Commit

Permalink
Python pandas dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed May 20, 2020
1 parent da25a2a commit 19eb48c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 12 deletions.
15 changes: 15 additions & 0 deletions pandas/df_access_column.py
Original file line number Diff line number Diff line change
@@ -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']]
15 changes: 15 additions & 0 deletions pandas/df_access_rows.py
Original file line number Diff line number Diff line change
@@ -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])
11 changes: 11 additions & 0 deletions pandas/df_creation1.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions pandas/df_creation2.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions pandas/df_creation3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# create pandas dataframe using csv file
import pandas as pd
df = pd.read_csv('student.csv')
print(df)
4 changes: 4 additions & 0 deletions pandas/df_creation4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# create python pandas using Excel file
import pandas as pd
df = pd.read_excel("result.xls","result")
print(df)
15 changes: 15 additions & 0 deletions pandas/df_creation5.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 3 additions & 12 deletions pandas/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -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))
df = pd.read_excel("result.xls","result")
print(df)

0 comments on commit 19eb48c

Please sign in to comment.