Win a copy of High Performance Python for Data Analytics this week in the Python forum!

Brandon Copeland

Greenhorn
+ Follow
since Jan 10, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brandon Copeland

Hello Everyone,

I have a question regarding for loops. I have a for loop that I would like to iterate through directories, subdirectories, and files looking for .*gz file extensions and then unpacking them to a list which I would later like to turn into a Pandas data frame.

I'm using this loop:




After running the above-mentioned code, I get the following error message:

"NameError Traceback (most recent call last)
<ipython-input-5-40ae48c7e923> in <module>()
10 pdFrame.append(value)
11 data_frame = pd.concat(pdFrame, axis=1, ignore_index=False)
---> 12 data_frame.to_csv('final_samples.csv', header=True)
13
14

NameError: name 'data_frame' is not defined"

From what I found so far, it seems like one of my variables is not being defined because my if clause is not being evaluated as true. I have tried initializing the data_frame variable outside of the loop, however that hasn't fixed the problem. Can someone possibly help me with this?

What I have tried:

I have tried using the following loop to check if my value is not null as follows:


2 weeks ago
Hello everyone,

I was hoping that someone here may be able to help me. I would like to map to entities together from a json file and use them as headers in a pandas data frame. For example, I would like to first map the two objects in the picture below:



As you can see in the json file, I want to map the 'file_name' to the 'entity_submitter_id' then I would like to display the 'entity_submitter_id' to the column headers in my data frame. I have tried the following code to try and reproduce this below:



When I print the head of the data frame, you can see the column headers are a mix of characters. Can anyone share how I can change those headers to the 'entity_submiter_id' in the json file? Your help would be much appreciated. Thanks in advance for any help!
2 weeks ago