percentage

Pandas get frequency of item occurrences in a column as percentage

Pandas get frequency of item occurrences in a column as percentage Question: I want to get a percentage of a particular value in a df column. Say I have a df with (col1, col2 , col3, gender) gender column has values of M, F, or Other. I want to get the percentage of M, F, …

Total answers: 5

Getting a percentage of files in a folder

Getting a percentage of files in a folder Question: I wrote a script, and I assigned part of it to select random sample of 10% of the files in a dir and copy them to a new dir. This is my method below, but it gives less than 10% (~9.6%) each time, and never the …

Total answers: 1

Pandas – get first n-rows based on percentage

Pandas – get first n-rows based on percentage Question: I have a dataframe i want to pop certain number of records, instead on number I want to pass as a percentage value. for example, df.head(n=10) Pops out first 10 records from data set. I want a small change instead of 10 records i want to …

Total answers: 5

pandas: how to get the percentage for each row

pandas: how to get the percentage for each row Question: When I use pandas value_count method, I get the data below: new_df[‘mark’].value_counts() 1 1349110 2 1606640 3 175629 4 790062 5 330978 How can I get the percentage for each row like this? 1 1349110 31.7% 2 1606640 37.8% 3 175629 4.1% 4 790062 18.6% …

Total answers: 4

Calculating and creating percentage column from two columns

Calculating and creating percentage column from two columns Question: I have a df (Apple_farm) and need to calculate a percentage based off values found in two of the columns (Good_apples and Total_apples) and then add the resulting values to a new column within Apple_farm called ‘Perc_Good’. I have tried: Apple_farm[‘Perc_Good’] = (Apple_farm[‘Good_apples’] / Apple_farm[‘Total_apples’]) *100 …

Total answers: 2

How do I print a '%' sign using string formatting?

How do I print a '%' sign using string formatting? Question: I’ve made a little script to calculator percent; however, I wish to actually include the % within the message printed… Tried this at the start – didn’t work… oFile.write("Percentage: %s%"n" % percent) I then tried "Percentage: %s"%"n" % percent" which didn’t work. I’d like …

Total answers: 6

Convert percent string to float in pandas read_csv

Convert percent string to float in pandas read_csv Question: Is there a way to convert values like ‘34%’ directly to int or float when using read_csv in pandas? I want ‘34%’ to be directly read as 0.34 Using this in read_csv did not work: read_csv(…, dtype={‘col’:np.float}) After loading the csv as ‘df’ this also did …

Total answers: 2

how to calculate percentage in python

how to calculate percentage in python Question: This is my program print” Welcome to NLC Boys Hr. Sec. School ” a=input(“nEnter the Tamil marks :”) b=input(“nEnter the English marks :”) c=input(“nEnter the Maths marks :”) d=input(“nEnter the Science marks :”) e=input(“nEnter the Social science marks :”) tota=a+b+c+d+e print”Total is: “, tota per=float(tota)*(100/500) print “Percentage is: …

Total answers: 10