import pandas as pd
import sys
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
Python version 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] Pandas version 1.3.5
# Create DataFrame
d = [1,2,3,4,5,6,7,8,9]
df = pd.DataFrame(d, columns = ['Number'])
df
Number | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
3 | 4 |
4 | 5 |
5 | 6 |
6 | 7 |
7 | 8 |
8 | 9 |
# Export to Excel
df.to_excel('Datafiles/Lesson10.xlsx', sheet_name = 'testing', index = False)
print('Done')
Done
# 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()
Number | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
3 | 4 |
4 | 5 |
df.dtypes
Number int64 dtype: object
df.tail()
Number | |
---|---|
4 | 5 |
5 | 6 |
6 | 7 |
7 | 8 |
8 | 9 |
df.to_json('Datafiles/Lesson10.json')
print('Done')
Done
# Your path will be different, please modify the path below.
jsonloc = r'Datafiles/Lesson10.json'
# read json file
df2 = pd.read_json(jsonloc)
df2
Number | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
3 | 4 |
4 | 5 |
5 | 6 |
6 | 7 |
7 | 8 |
8 | 9 |
df2.dtypes
Number int64 dtype: object
This tutorial was created by HEDARO