'AttributeError: 'Series' object has no attribute 'seek'
I am trying to get the latest file name and its path so that I can select the latest file for processing. By latest I mean folder name and not per creation date.
Folders are created as:
03Mar22.zip
06Mar22.zip
10Mar22.zip
13Mar22.zip
The value stored in latestfilepath is 'C:/Users/ ABC /OneDrive - DEF /Run #1 PQR/13Mar22.zip'
When I am using the variable that to parse the path then I am getting error as (AttributeError: 'Series' object has no attribute 'seek') but when I am writing the Path directly then the code runs fine. Can you please help me in identifying the issue?
The code that I am using is:
path = 'C:/Users/ABC/OneDrive - DEF/Run #1 PQR'
filesname = [f for f in os.listdir(path) if f.endswith('.zip')]
filepath = list(glob.glob(path+'\*.zip'))
jobfilelist = pd.DataFrame(list(zip(filesname,filepath)), columns = ['Names', 'Path'])
jobfilelist['Foldername'] = jobfilelist['Names'].str.split('.').str[0]
jobfilelist['Date'] = pd.to_datetime(jobfilelist['Foldername'])
LatestDate = jobfilelist['Date'].max()
jobfilelist = jobfilelist.loc[jobfilelist ['Date'] == LatestDate]
latestfilname = jobfilelist['Names']
latestfilepath = "'"+path +"/"+ latestfilname+"'"
extractZip = ZipFile(latestfilepath)
The error is:
AttributeError Traceback (most recent call last)
<ipython-input-34-568a6494aeee> in <module>
3 #extractZip1 = 'C:/Users/ABC/OneDrive - DEF/Run #1 PQR/13Mar22.zip'
4
----> 5 extractZip = ZipFile(latestfilepath)
6
7 #extractZip = ZipFile('C:/Users/ABC/OneDrive - DEF/Run #1 PQR/13Mar22.zip')
~\AppData\Local\Continuum\anaconda3\lib\zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel)
1223 try:
1224 if mode == 'r':
-> 1225 self._RealGetContents()
1226 elif mode in ('w', 'x'):
1227 # set the modified flag so central directory gets written
~\AppData\Local\Continuum\anaconda3\lib\zipfile.py in _RealGetContents(self)
1286 fp = self.fp
1287 try:
-> 1288 endrec = _EndRecData(fp)
1289 except OSError:
1290 raise BadZipFile("File is not a zip file")
~\AppData\Local\Continuum\anaconda3\lib\zipfile.py in _EndRecData(fpin)
257
258 # Determine file size
--> 259 fpin.seek(0, 2)
260 filesize = fpin.tell()
261
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
5177 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5178 return self[name]
-> 5179 return object.__getattribute__(self, name)
5180
5181 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'seek'
Solution 1:[1]
Thank you @ Azro,
I have got the solution... As you said I edited code for latestfilname as
latestfilname = jobfilelist['Names'].values[0]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sanjeev |
