AttributeError: DataFrame object has no attribute path

2024/9/21 2:43:51

I'm trying incrementally to build a financial statement database. The first steps center around collecting 10-Ks from the SEC's EDGAR database. I have code for pulling the relevant 8-Ks, 10-Ks, and 10-Qs by CIK number and accession number, and retrieving the relevant excel spreadsheet. The code below is now centering on trying to create a folder within a directory, then name the folder with the CIK code, then pull the spreadsheet from the EDGAR database, and save the spreadsheet to the folder with the CIK code. My example is a csv file I'm calling "accessionnumtest.csv", which has headings:

company_name,report_type,cik,date,cik_accession

and data:

4Less Group, Inc.,10K/A,1438901,11/27/2019,edgar/data/1438901/000121390019024801.txt

AB INTERNATIONAL GROUP CORP.,10K,1605331,10/22/2019,edgar/data/1605331/000166357719000384.txt

ABM INDUSTRIES INC /DE/,10K,771497,12/20/2019,edgar/data/771497/000162828019015259.txt

ACTUANT CORP,10K,6955,10/29/2019,edgar/data/6955/000000695519000033.txt

my code is below

import os
import pandas as pdpath = os.getcwd()folder_path = "C:/metricdatadb/"df = pd.read_csv("accessionnumtest.csv")folder_name = df['cik']
print(folder_name)for row in df.iterrows():dir = df.path.join(folder_path, folder_name)os.makedirs(dir)

This code is giving me, AttributeError: 'DataFrame' object has no attribute 'path' error. I have renamed the path, checked for whitespace in the headers. Any suggestions are appreciated.

Answer

Regarding the error: os.path.join. Not pd.path.join. You are calling the wrong module.

That being said, your code is not doing what you are trying to do regardless of the error. folder_name will not update for each row. You could do row.cik to get the value for each iterrows()

dir = os.path.join(folder_path, row.cik)
https://en.xdnf.cn/q/119251.html

Related Q&A

two DataFrame plot in a single plot matplotlip

I want to plot two DataFrame in a single plot.Though, I have seen similar post but none seems to work out. First 5 rows of my dataframe looks like this: df1name type start stop stran…

Automate `lxc-attach` through ssh with Python

Question: How do I automate this process, and include all of the password prompts? Machine 1> ssh user2@machine2password: Machine 2> lxc-attach -n 0x1000 Container> ssh user3@machine3password…

Value of a key in a Python dictinary is not updating [duplicate]

This question already has answers here:Appending a dictionary to a list - I see a pointer like behavior(3 answers)Python The appended element in the list changes as its original variable changes(1 answ…

Python - __init__() missing 1 required positional argument:

Im kinda new to python and I cant get past this error: Traceback (most recent call last):File "***", line 63, in <module>bst = Node() TypeError: __init__() missing 1 required positional…

discord py - Custom command prefix doesnt work (no command run)

i have a problem that i cant solve. Im trying to add a prefix switcher for all guilds, that uses my bot. So Ive done that, but currently no command gets triggered and I cant find a solution since hours…

How to use sep parameter in .format?

I just started learning python and Im experimenting new things. isim = input("Name:") soyad = input("Surname:") yaş = input("Age:") edu = input("Education:") ge…

Python table classification

I have different type of data for example:4.5,3.5,U1 4.5,10.5,U2 4.5,6,U1 3.5,10.5,U2 3.5,10.5,U2 5,7,U1 7,6.5,U1I need output:U1: [[4.5, 3.5], [4.5, 6], [5, 7], [7, 6.5]] U2: [[4.5, 10.5], [3.5, 10.5]…

python json.loads / json.load truncates nested json objects?

given the following code: import json foo = {"root":"cfb-score","children":{"gamecode":{"attribute":"global-id"},"gamestate":{&quo…

How to make an encrypted executable file

I have made a tool/program on Ubuntu written in Python. I want to give this to my friend to test on his PC, but I dont want to share the source code.This program has many folders and many .py files. Is…

Organizing pythonic dictionaries for a JSON schema validation

Scenario: I am trying to create a JSON schema validator in python. In this case, I am building a dictionary which contain the information that will be used for the validation.Code:import json import os…