Issue
I have added a Total column using
df['Total'] = df[list(df.columns)].sum(axis=1)
My dataframe is
H1 H2 H3 Total
A 1.643910e+10 5.403600e+09 1.090100e+09 2.293280e+10
B 3.876800e+09 1.056970e+10 6.152400e+09 2.059890e+10
C 2.126470e+10 1.077500e+09 2.858000e+08 2.262800e+10
D 3.911600e+09 3.309300e+09 8.170000e+07 7.302600e+09
and the column shows correctly but it is not in the info()
command, so I cannot use it with a plot. Same issue with the column containing A, B, C, D.
df.info()
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 H1 27 non-null float64
1 H2 27 non-null float64
2 H3 27 non-null float64
dtypes: float64(3)
I might need to use inplace = True
, but where?
Thanks for the help.
I expect to run df.info()
and actually see the first and the Total columns. Right now I only see the original 3 columns.
Solution
It could happen if you ran
df.info()
before you ran the code to create the Total column, or edited the df['Total']
after you ran the df.info()
You can try to restart the Kernel and restart and run all the notebook again. ( Assuming you are working on Jupyter notebook)
Second, Make sure that you got the Total Column first, and after that you can run this code to get the index as a column
df = df.reset_index()
If you reset the index then you tried to run the originl code to create the Total column,it will give you an error
You don't need to use inplace = True
here as you are defining a new column with its name
df['Total'] = df[list(df.columns)].sum(axis=1)
So, try to restart your script or notebook and make sure creating the total column is ran before df.info()
Also, try df.describe()
and see if Total column appears in it as it shows only numerical columns
Answered By - SHENOOOO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.