filmov
tv
Python Pandas DataFrame output as pickle & using Excel or MySQL table as source using to_pickle()

Показать описание
We can create Python pickle file by using data from Pandas DataFrame. We will first create one Pandas DataFrame by using some sample data.
import pandas as pd
df=pd.DataFrame(data={'id': [1, 2, 3],
'name': ['John Deo', 'Max Ruin', 'Arnold'],
'class': ['Four', 'Three', 'Three'],
'mark': [75, 85, 55],
'gender': ['female', 'male', 'male']})
From MySQL database using read_sql()
We can connect to MySQL database by using SQLAlchemy engine and after connection we will create our DataFrame by using data from sample table by using read_sql.
from sqlalchemy import create_engine
sql="SELECT * FROM student LIMIT 0,10"
Excel or CSV file to pickle
From excel file we can create pickle file by first creating the dataframe by reading the excel file by using the method read_excel()
Similarly we can read csv file and generate pickle file
#pandas_to_pickle #dataframetopickle #pandaspickle #plus2net #pandas #datascience #pandastutorials
import pandas as pd
df=pd.DataFrame(data={'id': [1, 2, 3],
'name': ['John Deo', 'Max Ruin', 'Arnold'],
'class': ['Four', 'Three', 'Three'],
'mark': [75, 85, 55],
'gender': ['female', 'male', 'male']})
From MySQL database using read_sql()
We can connect to MySQL database by using SQLAlchemy engine and after connection we will create our DataFrame by using data from sample table by using read_sql.
from sqlalchemy import create_engine
sql="SELECT * FROM student LIMIT 0,10"
Excel or CSV file to pickle
From excel file we can create pickle file by first creating the dataframe by reading the excel file by using the method read_excel()
Similarly we can read csv file and generate pickle file
#pandas_to_pickle #dataframetopickle #pandaspickle #plus2net #pandas #datascience #pandastutorials