1

I have a dataframe of 300 columns, I'm trying to calculate the mean of the columns in this dataframe, but I don't know how to change the columns.

count=0
for i in range(0,len(df)):
  count=count+1
  mean = statistics.mean(df.A1)
  print('C',count, " ", mean, sep= "") 

I need to get the column names from A1 to A300 row by row. I didn't want to do this manually

My dataframe columns like A1,A2,A3.. A.300

how can i step by step change this columns name?

gorkemco
  • 11
  • 2
  • *I'm trying to calculate the mean of the columns in this dataframe*: have you tried `df.mean()`, no need to iterate. – mozway Aug 01 '21 at 19:09
  • Does this answer your question? [pandas get column average/mean](https://stackoverflow.com/questions/31037298/pandas-get-column-average-mean) – mozway Aug 01 '21 at 19:11

1 Answers1

1

Just iterate through columns,

cols = df.columns
for col in cols:
  mean = df[col].mean()
  print(col, mean) 
RG_RG
  • 349
  • 5
  • 8