How to create a pandas dataframe from DXF attributes? #315
Unanswered
Shilpa-Dongray
asked this question in
Q&A
Replies: 2 comments
-
this is more of a pandas question than a dxf question because you have already been able to extract the data you want into a list of dictionaries. what I think you want to do is first collect all the dxfattribs of all the entities into a list, then create a single data frame: rows = [e.dxfattribs() for entity in modelspace]
df = pd.DataFrame(rows)
print(df) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for your reply.
…On Fri, 22 Jan 2021 at 00:03, Matt Broadway ***@***.***> wrote:
this is more of a pandas question than a dxf question because you have
already been able to extract the data you want into a list of dictionaries.
I think the issue could be that your dict_to_df() function takes a single
dictionary, so will of course give you a single row.
what I think you want to do is first collect all the dxfattribs of all the
entities into a list, then create a single data frame:
rows = [e.dxfattribs() for entity in modelspace]df = pd.DataFrame(rows)print(df)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#315 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANRNBANF6JKB7FENHF7DRMLS3AX37ANCNFSM4WIBJPIA>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I have a query with ezdxf.
Below is my code
import ezdxf
import pandas as pd
dwg_file = ezdxf.readfile(r'input.dxf')
modelspace = dwg_file.modelspace()
for entity in modelspace:
dxf_type = entity.dxftype()
p = entity.dxfattribs()
print(p)
The output is shown :
{'handle': '29C', 'owner': '1F', 'layer': 'PDF_Other 3', 'color': 14, 'true_color': 10944512, 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A2', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A3', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A4', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A5', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A6', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A7', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A8', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2A9', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2AA', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2AB', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2AC', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2AD', 'owner': '1F', 'layer': 'PDF_Sewer Manholes', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B1', 'owner': '1F', 'layer': 'PDF_Water Hydrant', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B2', 'owner': '1F', 'layer': 'PDF_Water Hydrant', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B4', 'owner': '1F', 'layer': 'PDF_Water Hydrant', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B5', 'owner': '1F', 'layer': 'PDF_Water Hydrant', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B6', 'owner': '1F', 'layer': 'PDF_Water Hydrant', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B8', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2B9', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BA', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BB', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BC', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BD', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BE', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2BF', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2C0', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2C1', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
{'handle': '2C2', 'owner': '1F', 'layer': 'PDF_Water System Valve', 'transparency': 33554559, 'elevation': Vector(0.0, 0.0, 0.0), 'extrusion': Vector(0.0, 0.0, 1.0), 'pattern_name': 'SOLID', 'solid_fill': 1, 'associative': 0, 'hatch_style': 0, 'pattern_type': 1}
The question is
How can I create a pandas dataframe out of this output?
Below is the code i tried. Only last line gets picked up in the dataframe.
def dict_to_df(p):
df=pd.DataFrame(p.items())
df.set_index(0, inplace=True)
return df
print(df)
The output is
**handle owner layer transparency elevation extrusion
0 2C2 1F PDF_Water System Valve 33554559 0.0 0.0
1 2C2 1F PDF_Water System Valve 33554559 0.0 0.0
2 2C2 1F PDF_Water System Valve 33554559 0.0 1.0
3 2C2 1F PDF_Water System Valve 33554559 0.0 0.0
4 2C2 1F PDF_Water System Valve 33554559 0.0 0.0
5 2C2 1F PDF_Water System Valve 33554559 0.0 1.0
pattern_name solid_fill associative hatch_style pattern_type
0 SOLID 1 0 0 1
1 SOLID 1 0 0 1
2 SOLID 1 0 0 1
3 SOLID 1 0 0 1
4 SOLID 1 0 0 1
5 SOLID 1 0 0 1**
Page8Scaled.zip
Thanks
Shilpa
Beta Was this translation helpful? Give feedback.
All reactions