Pandas

Python Pandas
Pandas : Python Data analysis tool.

Getting the version of Pandas
import pandas as pd 
print("Pandas Version : ",pd.__version__)
Filtering columns and create new DataFrame
my_new = my_data.filter(['equipment','category'],axis=1)
OR
cols=['MATH','ENGLISH']
my_new=my_data[cols]
Displaying columns of the DataFrame
print(my_new.columns)
Number of rows in DataFrame.
print(len(my_new))
DataFramePandas DataFrame
Settings Managing DataFrame display option values
apply Applying function along an Axis or elements
atGet and Set data using rows and columns
astypeCast to a specified dtype
cutUsing segments for categorizing values
describeDescriptive statistics of DataFrame or series
groupbycombining data and aggregate functions
headFirst n rows of the DataFrame
isnullChecking NaN or None data
ilocValues at different position using integer
locValues at different position using column label
filterCondition based filtering of rows
fillnaFilling NaN data
mergecombining DataFrame and aggregate functions
methodsPandas DataFrame methods
nlargestn elements in descending sorted values
maskconditional replacement of data
queryFiltering data by using conditions
sort_valuesSort columns in ascending or descending
countNumber of rows or columns with different options
sumSum of values of requried axis
set_indexCreating index using one or more columns
maxMax value of requried axis
minMin value of requried axis
notnullNot None and Not Null values checking
reset_indexRemove index of the DataFrame
value_countscounts of unique values
uniqueUnique Data of a column
whereData updation based on condition


Creating Pandas DataFrame by using Numpy ndarray

Exercises
Exercise1Basic data handling , DataFrame
Exercise-AdvUsing groupby and merge of DataFrame
Exercise2Using str.contains(), max(), min(),len() of DataFrame
Exercise3Using date and time functions with groupby of DataFrame
Exercise3-2Using date and time functions of DataFrame
Exercise3-3Using date and time functions with groupby
Exercise3-4Using date and time with where timedelta64

I/O : Input and output Data from Pandas ( Excel , MySQL , JSon)

We can’t store data in Pandas DataFrame. We can process the data by using Pandas DataFrame after reading data from different sources. Similarly after processing we can save data in different files or database by using available tools.
Data input and output from Pandas DataFrame
Filtering records
locValues at different position using column label
rowsFiltering rows based on data

handling string using str methods

str.containsstring matching against data columns
str.contains.sumMax Min Sum of any column
Convert CaseLower to Upper and vice versa
split()Breaking string using delimiter
slice()Substring by breaking string
cat()Concatenate strings
count()Number of occurences of pattern
replace()Replace part of string by regex
len()Length of the data in our DataFrame
Plotting Graphs using Data
Plotting graphsCreating different type of graphs using DataFrame
ExerciseGraph using data from Excel file
Managing Date
Pandas Date and time Managing Date and time in Pandas DataFrame

Excel to MySQL

Excel to MySQL
import pandas as pd 
my_data = pd.read_excel('D:\emp.xlsx')
# reading data from root of D drive. 
from sqlalchemy import create_engine
engine = create_engine("mysql+mysqldb://userid:password@localhost/my_tutorial")

### Creating new table emp or appending existing table 
my_data.to_sql(con=engine,name='emp',if_exists='append')

MySQL to Excel

MySQL to Excel
import pandas as pd 

from sqlalchemy import create_engine
engine = create_engine("mysql+mysqldb://userid:password@localhost/my_tutorial")

sql="SELECT * FROM emp "
my_data = pd.read_sql(sql,engine )

my_data.to_excel('D:\emp2.xlsx')

Columns and rows

columnsList of column headers of a DataFrame
renamerename columns of DataFrame
add_suffixadding suffix to column names of a DataFrame
add_prefixadding prefix to column names of a DataFrame
dropDelete columns or rows

Data Cleaning

Various methods in Pandas to clean data. Read from different sources then remove or fill with matching data in rows and columns

Get the list of all functions of Pandas. ( Used dir() )
import pandas as pd
print(len(dir(pd))) # 139
for i in dir(pd):
    print(i)
Pandas DataFrame


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer