python pandas: assigning a json data to a data frame entry returns error “Incompatible indexer with...
up vote
0
down vote
favorite
As a newbie to python I'm struggling with an error "Incompatible indexer with Series".
I'm reading a entry from a postgreSQL database:
df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))
...output:
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>
The column in the postgreSQL data base shows type 'jsonb':
This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict
... and with the last code line I get that error
ValueError: Incompatible indexer with Series
What do I do wrong?
json pandas jsonb
|
show 11 more comments
up vote
0
down vote
favorite
As a newbie to python I'm struggling with an error "Incompatible indexer with Series".
I'm reading a entry from a postgreSQL database:
df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))
...output:
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>
The column in the postgreSQL data base shows type 'jsonb':
This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict
... and with the last code line I get that error
ValueError: Incompatible indexer with Series
What do I do wrong?
json pandas jsonb
1
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is usedf.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
1
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
1
the workaround? this one:if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51
|
show 11 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
As a newbie to python I'm struggling with an error "Incompatible indexer with Series".
I'm reading a entry from a postgreSQL database:
df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))
...output:
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>
The column in the postgreSQL data base shows type 'jsonb':
This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict
... and with the last code line I get that error
ValueError: Incompatible indexer with Series
What do I do wrong?
json pandas jsonb
As a newbie to python I'm struggling with an error "Incompatible indexer with Series".
I'm reading a entry from a postgreSQL database:
df_postgresDB = pd.read_sql_query('SELECT * FROM public.json_view',con=<...>)
exampleKey = 'FPB-83160'
jsonCol = 'efforts'
AreasDict = df_postgresDB.loc[exampleKey, jsonCol]
print('AreasDict=', AreasDict)
print('type(AreasDict)=', type(AreasDict))
...output:
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
type(AreasDict)= <class 'dict'>
The column in the postgreSQL data base shows type 'jsonb':
This 'AreasDict' is used in the function of another project I want to call and re-use for my project. But in my project, I need to build up the data from another source. So I create a data frame and try to assign that 'AreasDict' ()...
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = AreasDict
... and with the last code line I get that error
ValueError: Incompatible indexer with Series
What do I do wrong?
json pandas jsonb
json pandas jsonb
edited Nov 20 at 9:00
asked Nov 20 at 8:49
Joe Phi
8510
8510
1
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is usedf.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
1
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
1
the workaround? this one:if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51
|
show 11 more comments
1
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is usedf.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
1
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
1
the workaround? this one:if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51
1
1
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use
df.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use
df.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
1
1
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
1
1
the workaround? this one:
if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51
the workaround? this one:
if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51
|
show 11 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
In pandas non scalar values are poorly supported - many function should failed.
Solution is convert to list
for list of dictionary:
jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389252%2fpython-pandas-assigning-a-json-data-to-a-data-frame-entry-returns-error-incomp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
In pandas non scalar values are poorly supported - many function should failed.
Solution is convert to list
for list of dictionary:
jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...
add a comment |
up vote
1
down vote
accepted
In pandas non scalar values are poorly supported - many function should failed.
Solution is convert to list
for list of dictionary:
jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
In pandas non scalar values are poorly supported - many function should failed.
Solution is convert to list
for list of dictionary:
jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...
In pandas non scalar values are poorly supported - many function should failed.
Solution is convert to list
for list of dictionary:
jsonCol = 'j'
exampleKey = 'key'
AreasDict= {'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane': 800, 'MANO BTSSM': 0}
column_names = ['issue_key', jsonCol]
df = pd.DataFrame(index=range(1,2), columns=column_names)
df.iloc[0, 0] = exampleKey
df.iloc[0, 1] = [AreasDict]
print (df)
issue_key j
1 key [{'4G NeVe': 0, '4G FT ET': 400, '4G C-Plane':...
answered Nov 20 at 9:43
jezrael
315k22256333
315k22256333
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389252%2fpython-pandas-assigning-a-json-data-to-a-data-frame-entry-returns-error-incomp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Problem is in pandas is not recomended store dicts in DataFrame column, but one possible solution is use
df.iloc[0, 1] = [AreasDict]
– jezrael
Nov 20 at 9:04
Yes, that turns it into class 'list' !! I'll try that in my project that calls the function using it and let you know.
– Joe Phi
Nov 20 at 9:09
So it working for you nice? It is what you need?
– jezrael
Nov 20 at 9:10
1
I still have to try that principle in my 'real' project that calls the shared function and see if that function eats it.Will let you know.
– Joe Phi
Nov 20 at 9:11
1
the workaround? this one:
if isinstance(AreasDict, str) : then AreasDict = ast.literal_eval(AreasDict
– Joe Phi
Nov 20 at 13:51