1

I'm very new to Python, but cannot figure out this simple ask. I have a Pandas DataFrame that contains 8 values in two different columns. I'm trying to gather these values into their own lists so I can run stats on them.

n1 = df.iloc[0:4,2:3]
n2 = df.iloc[4:9,13:14]
total = pd.concat([n1,n2], axis=0)

but at this point my 'total' df is riddled with NaN. I've tried

mean = total.mean(axis=0, numeric_only = int)

but it doesnt work.

How can I get the two portions of the df into a list without NaN or how can I calculate stats on a df riddled with NaNs?

Thank you!

St. Jimmy
  • 73
  • 8
  • Please have a look at [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [edit] your question with a [mcve] showing sample input and expected output so that we can understand your question – G. Anderson Feb 10 '23 at 19:07
  • Look into the documentation of pandas, in particular: `df.mean()` – coco18 Feb 10 '23 at 19:14
  • Yep, I read the pandas doc and df.mean() in particular. I'm doing something wrong with the input data somehow, but I don't know what. I think it has to do with how I am preprocessing the lists. Any insights into why it's not working? Thanks – St. Jimmy Feb 10 '23 at 22:16

1 Answers1

1

If you want to extract single columns, don't use slice (13:14 -> 13)

n1 = df.iloc[0:4, 2]
n2 = df.iloc[4:9, 13]
total = pd.concat([n1, n2], axis=0)

Output:

>>> total
0    42
1    76
2    54
3    51
4    56
5    63
6    56
7    80
8    93
dtype: int64

>>> total.mean()
63.44444444444444
Corralien
  • 109,409
  • 8
  • 28
  • 52