Pandas ExcelFile function close() in Python
The Pandas ExcelFile function close() used to close IO if necessary. It does not return any value.
close() function
 1 import pandas as pd
 2 
 3 # reading file written using to_excel() of DataFrame
 4 exl = pd.ExcelFile('out.xlsx')
 5 res = exl.parse('Data', usecols = [1, 2])
 6 print('The excel content :')
 7 print(res)
 8 
 9 # close ExcelFile
 10 cls = exl.close()
In the above example, a ExcelFile object is created by passing a filename. An object is parsed and retrieve the content. A close() function is called that close the io object.
Output
 1 The excel content :
 2   Unnamed: 0  C1  C2
 3 0         R1  11  12
 4 1         R2  21  22
 5 2         R3  31  33
 6 3         R4  41  44

Example 2

Example 2
 1 import pandas as pd
 2 
 3 # reading file written using to_excel() of DataFrame
 4 exl = pd.ExcelFile('out.xlsx')
 5 res = exl.parse('Data', usecols = [3, 4])
 6 print('The excel content :')
 7 print(res)
 8 
 9 # close ExcelFile
 10 cls = exl.close()
In the above example, a ExcelFile object is created by passing a filename. An object is parsed and retrieve the content. A close() function is called that close the io object.
Output
 1 The excel content :
 2   Unnamed: 0  C3  C4
 3 0         R1   A   W
 4 1         R2   B   X
 5 2         R3   C   Y
 6 3         R4   D   Z
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us