I am trying to convert a dict to Pandas DataFrame as the following:
JavaScript
x
23
23
1
dff = pd.DataFrame(
2
{
3
'CEO': 'ucMMe Mhll',
4
'address': 'vs5dlt3 B Se1kC eve0nre',
5
'address2': '-',
6
'city': 'a CSatanral',
7
'companyName': 'Agilent Technologies Inc.',
8
'country': 'nUatei tdetSs',
9
'description': "tns oo el' yty",
10
'employees': 17124,
11
'exc': 'gdgdgd',
12
'industry': 'sgeiTeotiroaLbtans r',
13
'issueType': 'abc',
14
'phone': '14087832319',
15
'primarySicCode': 4008,
16
'sector': ',atnSii Scilcofe,nnse TecisaPliinafs cedorhv cre',
17
'securityName': 'elooIne.nen htc iisTcgAgl',
18
'state': 'ailairofnC',
19
'symbol': 'A',
20
'tags': ['nllh he', 'gth', 'acsl', 'isiad', 'nr aitT'],
21
'website': 'win.gcm.',
22
'zip': '0752501-19'} )
23
And when I print out the DataFrame, I see the following output:
JavaScript
1
2
1
print(dff)
2
I expect to see 1 row only in the DataFrame but it gives 5. And I cannot understand why. What am I doing wrong here?
Advertisement
Answer
You’re not doing anything wrong. Since tags
is a list, Pandas broadcasts all other fields to same size as tags
and make a dataframe. You can do:
JavaScript
1
2
1
pd.Series(your_dict).to_frame().T
2
Or wrap your dict around []
indicating it’s a row (record orient):
JavaScript
1
2
1
pd.DataFrame([your_dict])
2