Home > database >  how to remove the value counts in pandas
how to remove the value counts in pandas

Time:02-20

I have a dataframe with unique numbers and their value counts in a dataframe. I would like to remove the value counts to get the mean of the numbers.

I have tried to convert it to a string and then slice it. randompicks2 = randompicks.to_string() then randompicks2 = randompicks2[0:38] which gives me the 6 digit random number without the value counts, but I can't convert the string to a number, or do any math's on them. Below is the data set. The random numbers are from 1-69 and if the values change to much it will add or subtract an element in the string, so the strings can and will change every time.

So in the program I needed the value counts. And now I need to do some functions on the random numbers without the value counts messing up the data, for example doing mean, finding the sum, and so on. I have also tried to convert the string to a numpy array, and just straight slicing from the dataframe. randompicks2 = randompicks2[0:15] all I get back with that is the same dataframe below.

I just need the very top row of numbers,ie the 11,16,18,50,69,3

I added the dots to make the spacing correct.

... 11 ... 16 ... 28 ... 50 ... 69 ...... 3

0 61.0 NaN NaN NaN NaN NaN

1 NaN 43.0 NaN NaN NaN NaN

2 NaN NaN 35.0 NaN NaN NaN

3 NaN NaN NaN 35.0 NaN NaN

4 NaN NaN NaN NaN 42.0 NaN

5 NaN NaN NaN NaN NaN 51.0

some more sample data:using print(df).to_dict and print(df.columns)

{2: {0: 101.0, 1: nan, 2: nan, 3: nan, 4: nan}, 16: {0: nan, 1: 43.0, 2: nan, 3: nan, 4: nan}, 39: {0: nan, 1: nan, 2: 39.0, 3: nan, 4: nan}, 47: {0: nan, 1: nan, 2: nan, 3: 41.0, 4: nan}, 53: {0: nan, 1: nan, 2: nan, 3: nan, 4: 51.0}, 10: {0: nan, 1: nan, 2: nan, 3: nan, 4: nan}} Int64Index([2, 16, 39, 47, 53, 10], dtype='int64')

And some of the first few of the df that I draw the random numbers from.

0 1 2 3 4 5

2 101.0 6.0 NaN NaN NaN 43.0

3 97.0 11.0 NaN NaN NaN 51.0

4 89.0 19.0 2.0 NaN NaN 56.0

1 88.0 NaN NaN NaN NaN 57.0

6 68.0 26.0 1.0 NaN NaN 56.0

CodePudding user response:

Try this:

l = df.columns.tolist()
print(l)

Output:

[2, 16, 39, 47, 53, 10]

CodePudding user response:

You can just do list call

l = list(df)
  • Related