#!/usr/bin/env python # coding: utf-8 # ![Pandas Tutorial | Hedaro >](https://www.dropbox.com/s/220ncn0o5danuey/pandas-ipython-tutorials-hedaro.jpg?dl=1) # # Lesson 10 # * From DataFrame to Excel # * From Excel to DataFrame # * From DataFrame to JSON # * From JSON to DataFrame # In[1]: import pandas as pd import sys # In[2]: print('Python version ' + sys.version) print('Pandas version ' + pd.__version__) # # From DataFrame to Excel # In[3]: # Create DataFrame d = [1,2,3,4,5,6,7,8,9] df = pd.DataFrame(d, columns = ['Number']) df # In[4]: # Export to Excel df.to_excel('Datafiles/Lesson10.xlsx', sheet_name = 'testing', index = False) print('Done') # # From Excel to DataFrame # In[5]: # Path to excel file # Your path will be different, please modify the path below. location = r'Datafiles/Lesson10.xlsx' # Parse the excel file df = pd.read_excel(location, 0) df.head() # In[6]: df.dtypes # In[7]: df.tail() # # From DataFrame to JSON # In[8]: df.to_json('Datafiles/Lesson10.json') print('Done') # # From JSON to DataFrame # In[9]: # Your path will be different, please modify the path below. jsonloc = r'Datafiles/Lesson10.json' # read json file df2 = pd.read_json(jsonloc) # In[10]: df2 # In[11]: df2.dtypes #

This tutorial was created by HEDARO