0
$\begingroup$

I am generating a dataframe from a JSON file, this JSON file can come from 2 different sources, so the internal structure is slightly different, so what I am doing is first detecting the source and from there I do a set of operations that gives me a Dataframe

Everything is good until here (I thought), as when I print it in jupyter it shows me the way I wanted they look the same (structure), the problem goes when I loop through them,

I get completely different results (this df have each same number of columns, 7 columns)

enter image description here

When I loop:

In 1 I have only 2 columns in the other one I get all the columns.

I am looping:

for i, (index, row) in enumerate(df_trans.iterrows()):
    print(row)

Is there a way to see how is structure, I am quite confused of why the print of the df loops the same but when looping is not

EDIT

I notice that when I print the dataframe after a grouping I get the followin

df_summary_trans_cs.groupby(['Date'])['sale', 'refund','Balance'].agg('sum')

I get all the columns

but when I add the column

df_summary_trans_cs.groupby(['Date'])['sale', 'refund','Balance', 'Trans'].agg('sum')

I only get that column, the other 3 dissapears

$\endgroup$
  • $\begingroup$ Its possible that in the df that prints only 2 columns the other are set as index. Print df1.columns and df2.columns and see if they are the same. $\endgroup$ – yoav_aaa Aug 12 '18 at 12:18
  • $\begingroup$ @DaFanat both shows me Index(['detail', 'date', 'amount'], dtype='object') however when i do type() only 1 shows me pandas.core.frame.DataFrame but it doesnt have much sense as both I defined them as df = pd.DataFrame() $\endgroup$ – Manza Aug 12 '18 at 12:27
0
$\begingroup$

I finally got what was wrong, it has to do with the type in the series, so when i printed the whole dataframe the values where there, but the grouping was not been apply as it seems they were not number

I apply

df.MissingColumn = df.MissingColumn.astype(np.float64)

And this fixed the issue

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.