how to create a data table from a not estructured text file - python

I create a ngram from Python and the output its something like this:
'vida': 113, 'sistema': 104, 'economía': 91, 'nacional': 84, 'mujeres': 76, 'derechos': 75, 'salud': 75, 'paz': 67, 'colombia': 66, 'social': 66, 'trabajo': 63, 'protección': 62, 'política': 61, 'país': 55, 'acceso': 53, 'cambio': 49, 'sociedad': 49, 'derecho': 49, 'educación': 47, 'cuidado': 46, 'así': 45, 'productiva': 44, 'condiciones': 44, 'cultura': 41, 'participación': 39, 'agua': 39, 'gobierno': 38, 'desarrollo': 38, 'integral': 37, 'construcción': 37, 'personas': 37, 'naturaleza': 35, 'territorios': 35, 'popular': 35, 'público': 35, 'pública': 34, 'territorio': 33, 'pueblos': 33, 'servicios': 33, 'todas': 33, 'población': 33, 'indígenas': 32, 'garantizaremos': 32, 'climático': 31, 'vivienda': 31, 'justicia': 31, 'políticas': 31, 'través': 31, 'producción': 30, 'cultural': 30, 'empleo': 30, 'calidad': 29, 'internacional': 29, 'manera': 29, 'pacto': 28, 'públicos': 28, 'mediante': 28, 'impulsaremos': 28, 'plan': 27, 'procesos': 27, 'territorial': 26, 'seguridad': 26, 'reconocimiento': 26, 'igualdad': 25, 'conocimiento': 25, 'afrodescendientes': 25, 'economías': 25, 'toda': 25, 'sociales': 25, 'nivel': 25, 'garantizar': 25, 'comunidades': 25, 'atención': 25, 'uso': 25, 'territoriales': 25, 'tierra': 24, 'víctimas': 24, 'transición': 24, 'trabajadores': 24, 'mayor': 24, 'programas': 24, 'enfoque': 24, 'base': 24, 'democratización': 23, 'productividad': 23, 'arte': 23, 'negros': 23, 'avanzaremos': 23, 'rurales': 23, 'públicas': 23, 'formas': 23, 'sector': 23, 'formación': 23, 'garantía': 22, 'lucha': 22, 'palenqueros': 22, 'pensión': 22, 'fin': 22, 'transformación': 22, 'marco': 22, 'culturales': 22, 'género': 21, 'sistemas': 21, 'ambiental': 21, 'modelo': 21, 'mundial': 20, 'niños': 20, 'gran': 20, 'alimentaria': 20, 'zonas': 20, 'bajo': 20, 'reforma': 20, 'potencia': 19, 'crédito': 19, 'primera': 19, 'raizales': 19, 'mayores': 19, 'fundamental': 19, 'organizaciones': 19, 'educativo': 19, 'comunitarias': 19, 'ambientales': 19, 'espacio': 18, 'industria': 18, 'jóvenes': 18, 'infancia': 18, 'niñas': 18, 'patrimonio': 18, 'alimentación': 18, 'económica': 18, 'instrumentos': 18, 'bienes': 18, 'generación': 18, 'recursos': 18, 'proyectos': 18, 'promoveremos': 18, 'laboral': 18, 'deporte': 17, 'realidad': 17, 'diversidad': 17, 'humana': 17, 'reparación': 17, 'programa': 17, 'soberanía': 17, 'garantizando': 17, 'diálogo': 17, 'mercado': 17, 'regional': 17, 'económico': 16, 'saber': 16, 'campo': 16, 'campesinado': 16, 'tiempo': 16, 'parte': 16, 'familias': 16, 'energía': 16, 'autonomía': 16, 'local': 16, 'rural': 16, 'populares': 16, 'apoyo': 16, 'fortalecimiento': 16, 'libre': 15, 'oportunidades': 15, 'haremos': 15, 'rrom': 15, 'adultos': 15, 'basada': 15, 'capacidad': 15, 'millones': 15, 'libertad': 15, 'acuerdo': 15, 'superar': 15, 'valor': 15, 'energética': 15, 'fortaleceremos': 15, 'centros': 15, 'gestión': 15, 'ser': 15, 'garantías': 14, 'agenda': 14, 'corrupción': 14, 'nuevo': 14, 'crearemos': 14, 'hombres': 14, 'superior': 14, 'general': 14, 'tierras': 14, 'espacios': 14, 'capacidades': 14, 'ingresos': 14, 'nacionales': 14, 'mejorar': 14, 'prácticas': 14, 'servicio': 14, 'control': 14, 'alrededor': 13, 'desigualdad': 13, 'convivencia': 13, 'nación': 13, 'diversidades': 13, 'saberes': 13, 'puedan': 13, 'grandes': 13, 'institucionalidad': 13, 'áreas': 13, 'riesgo': 13, 'infraestructura': 13, 'financiamiento': 13, 'transporte': 13, 'cada': 13, 'particular': 13, 'red': 12, 'vivir': 12, 'defensa': 12, 'fundamentales': 12, 'democracia': 12, 'efectiva': 12, 'permita': 12, 'colombiana': 12, 'productores': 12, 'universal': 12, 'creación': 12, 'mínimo': 12, 'permitan': 12, 'especial': 12, 'articulación': 12, 'distribución': 12, 'regionales': 12, 'hacer': 12, 'actividades': 12, 'locales': 12, 'productos': 12, 'intercultural': 12, 'tecnologías': 12, 'entidades': 12, 'sectores': 12, 'memoria': 12, 'negocio': 11, 'física': 11, 'poblaciones': 11, 'violencia': 11, 'trabajos': 11, 'impuestos': 11, 'promoción': 11, 'frente': 11, 'cuidados': 11, 'bienestar': 11, 'digno': 11, 'reducción': 11, 'dentro': 11, 'investigación': 11, 'debe': 11, 'medidas': 11, 'implica': 11, 'comunitarios': 11, 'cobertura': 11, 'incluyendo': 11, 'nuevas': 11, 'autoridades': 11, 'aprovechamiento': 11
I want to create a cdv file from it, that cotain two columns "words" and "Count" in a csv file, Im looking for a way fo how to do it in Python o R
Thanks for the help!

In tidyverse, we can split by : with separate_rows and split the column again into two with separate
library(dplyr)
library(tidyr)
library(stringr)
tibble(col1 = str1) %>%
separate_rows(col1, sep = ",\\s*") %>%
separate(col1, into = c("key", "value"), sep = ":\\s*", convert = TRUE) %>%
mutate(key = str_remove_all(key, "'"))
-output
# A tibble: 261 × 2
key value
<chr> <dbl>
1 vida 113
2 sistema 104
3 economía 91
4 nacional 84
5 mujeres 76
6 derechos 75
7 salud 75
8 paz 67
9 colombia 66
10 social 66
# … with 251 more rows

You can try
x <- "the string in your question"
df <- read.table(textConnection(gsub("," ,"\n" , x)) , sep = ":")
write.csv(df, "myngram" , row.names = F)

Here is one more tidyverseapproach:
Same as #akrun we separate the rows by , , then we use str_extract from stringr package twice with regex:
library(tidyverse)
str1 %>%
as_tibble() %>%
separate_rows(value, sep=", ") %>%
mutate(key = str_extract(value, '[A-Za-z]+'),
value = as.numeric(str_extract(value, '[0-9]+')), .before=1)
key value
<chr> <dbl>
1 vida 113
2 sistema 104
3 econom 91
4 nacional 84
5 mujeres 76
6 derechos 75
7 salud 75
8 paz 67
9 colombia 66
10 social 66
# ... with 251 more rows

Related

how to detect the peaks above 23 using scipy

i have the random data in which i plotted graph for finding the peaks which is originated from zero i used this code
x = np.array([0, 7, 18, 24, 26, 27, 26, 25, 26, 16, 20, 16, 23, 33, 27, 27,
22, 26, 27, 26, 25, 24, 25, 26, 23, 25, 26, 24, 23, 12, 22, 11, 15, 24, 11,
12, 11, 27, 19, 25, 26, 21, 23, 26, 13, 9, 22, 18, 23, 26, 26, 25, 10, 22,
27, 25, 19, 10, 15, 20, 21, 13, 16, 16, 15, 19, 17, 20, 24, 26, 20, 23, 23,
25, 19, 15, 16, 27, 26, 27, 28, 24, 23, 24, 27, 28, 30, 31, 30, 9, 0, 11,
16, 25, 25, 22, 25, 25, 11, 15, 24, 24, 24, 17, 0, 23, 21, 0, 24, 26, 24,
26, 26, 26, 24, 25, 24, 24, 22, 22, 22, 23, 24, 26])
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
zero_locs = np.where(x==0) # find zeros in x
search_lims = np.append(zero_locs, len(x)) # limits for search area
diff_x = np.diff(x) # find the derivative of x
diff_x_mapped = diff_x > 0 # find the max's of x (zero crossover # points)
# from every zero, search for the first peak within the range of current
# zero location to next zero location
peak_locs = []
for i in range(len(search_lims)-1):
peak_locs.append(search_lims[i] +
np.where(diff_x_mapped[search_lims[i]:search_lims[i+1]]==0)[0][0])
fig= plt.figure(figsize=(19,5))
plt.plot(x)
plt.plot(np.array(peak_locs), x[np.array(peak_locs)], "x", color = 'r')
this is my code actually this is vehicle speed data for every 0 to maximum peak it is detecting correctly but the thing is it should detect above 26 i tried unable to get it. my graph output is
for starting point only it is detecting correctly remaining 3 points it should not be detected only the peak value 0 to above 26 only it has to detect how can i do it

Coverting Int64index to list or accessing list of lists

I have a list of lists but because of the Int64Index I cannot access it. Is there a way to access individual values or make it into a normal list?
data_exp = pd.read_csv(path+'/exp.csv')
exp_list=[]
for i in range (1,n+1):
check=data_exp.apply(lambda x: True if x['Set No.']==i else False, axis=1)
temp=[data_exp[check==True].index+1]
exp_list.append(temp)
del temp
display(exp_list)
The for loop just sort values based on a condition. The output is good but it is the format which is problamatic.
Gives me out put as follows:-
[[Int64Index([8, 11, 17, 20, 21, 27, 29, 36, 37, 38], dtype='int64')],
[Int64Index([1, 3, 7, 10, 14, 31, 33, 34, 35], dtype='int64')],
[Int64Index([5, 9, 12, 15, 19, 23, 25, 26, 28, 32], dtype='int64')],
[Int64Index([2, 4, 6, 13, 16, 18, 22, 24, 30, 39, 40], dtype='int64')]]
Thanks in advance
I'm not quite sure what you're doing to get the list of Int64Indexes, but you can access the numpy array underlying the index with the values property:
from pandas import Int64Index
l = [[Int64Index([8, 11, 17, 20, 21, 27, 29, 36, 37, 38], dtype='int64')],
[Int64Index([1, 3, 7, 10, 14, 31, 33, 34, 35], dtype='int64')],
[Int64Index([5, 9, 12, 15, 19, 23, 25, 26, 28, 32], dtype='int64')],
[Int64Index([2, 4, 6, 13, 16, 18, 22, 24, 30, 39, 40], dtype='int64')]]
print(l[0][0].values[0])

KeyError: 2 in qcut

I want to do bucketing on one of the column of my dataframe. I have 2 columns, Category & Rank.
I want to do bucketing in each category. So i first groupby on category & then use qcut on each group to do bucketing. After groupby, my dataframe's group looks like (final_data.groupby(['category'])['Ranks'].groups)
{'north': [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 13, 14, 17, 18, 19, 21, 22, 23, 24, 25, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44], 'south': [0, 5, 12, 15, 16, 20, 26, 27, 0, 1, 9, 10, 21, 26, 27, 28, 35, 45, 46, 47]}
I'm applying this code to bucketing
final_data.groupby(['category'])['Rank'].transform(lambda g: pd.qcut(g, q=[0.0, .1, .25, .5, .75, .9, 1.0], labels= ["Top 10", "11-25", "26-50", "50-75", "75-90" ,"Bottom10"]))
The above code is throwing the error

Divide Dataframe into 2 dataframe using index

I need to divide my dataframe into 2 dataframe based on their index
Df1 with this index:[5, 15, 22, 23, 24]
Df2 with this index:[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54]
Unable to find solution! Any help would be appreciated
If input is list of index values is possible use Index.isin in boolean indexing (if not exist some values in original index also working correct):
idx = [5, 15, 22, 23, 24]
mask = df.index.isin(idx)
df1 = df[mask]
df2 = df[~mask]
Solution with DataFrame.loc is possible without : and is necessary all values exist in original index:
L1 = [5, 15, 22, 23, 24]
L2 = [0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20,
21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54]
df1 = df.loc[L1]
df2 = df.loc[L2]
You can use .loc:
df_1 = df.loc[[5, 15, 22, 23, 24], :]
df_2 = df.loc[[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54], :]
Here is the documentation: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html

Trouble printing strings and percentages

Here's my Code:
from collections import Counter
Value = (3, 19, 23, 27, 36, 10, 25, 29, 39, 41, 9, 16, 20, 31, 34, 2, 8, 9, 33, 37, 4, 21, 27, 28, 35, 2, 12, 21, 23, 38, 4, 5, 12, 16, 20, 1, 8, 21, 33, 38, 1, 9, 12, 18, 36, 5, 17, 20, 22, 25, 14, 21, 27, 31, 41, 11, 12, 23, 28, 41, 9, 22, 25, 34, 35, 5, 12, 19, 22, 39, 5, 13, 14, 17, 33, 4, 16, 26, 27, 37, 9, 18, 31, 34, 39, 9, 17, 33, 35, 40, 16, 20, 22, 37, 40, 2, 14, 19, 22, 32, 4, 5, 21, 29, 36, 2, 9, 22, 32, 35, 9, 13, 24, 36, 40, 3, 7, 9, 10, 28, 4, 20, 21, 23, 41, 12, 18, 26, 28, 34, 3, 23, 24, 27, 37, 4, 5, 26, 34, 36, 3, 5, 15, 25, 34, 4, 7, 9, 23, 32, 5, 7, 19, 29, 34, 2, 4, 25, 34, 38, 1, 4, 24, 32, 33, 20, 23, 31, 37, 40, 1, 20, 31, 36, 37, 1, 18, 30, 32, 41, 4, 8, 24, 26, 33, 3, 12, 13, 27, 34, 3, 6, 16, 24, 28, 10, 17, 20, 30, 32, 8, 10, 27, 28, 29, 6, 21, 23, 30, 32, 1, 22, 29, 33, 36, 1, 6, 9, 28, 30, 9, 12, 14, 19, 31, 1, 2, 10, 29, 37, 2, 7, 19, 20, 27, 7, 9, 30, 35, 37, 14, 23, 25, 29, 30, 4, 11, 19, 27, 32, 11, 15, 23, 26, 35, 14, 18, 22, 26, 28, 4, 17, 18, 23, 40, 10, 11, 16, 37, 39, 2, 12, 15, 27, 29, 3, 11, 20, 21, 26, 11, 17, 29, 31, 38, 9, 14, 15, 31, 32, 14, 25, 29, 35, 40, 1, 5, 8, 17, 27, 6, 14, 16, 18, 20, 13, 15, 29, 33, 35, 10, 18, 26, 38, 41, 13, 16, 20, 26, 27, 4, 12, 27, 32, 33, 7, 10, 26, 30, 31, 5, 7, 17, 37, 38, 3, 6, 10, 27, 38, 5, 15, 23, 33, 36, 11, 15, 31, 34, 38, 8, 9, 11, 15, 25, 6, 7, 21, 30, 33, 4, 17, 21, 34, 35, 3, 8, 16, 22, 34, 5, 23, 28, 31, 39, 7, 18, 24, 33, 40, 5, 24, 30, 38, 41, 3, 11, 25, 27, 37, 19, 26, 34, 36, 40, 20, 27, 30, 32, 38, 1, 16, 17, 26, 30, 6, 11, 14, 17, 28, 11, 18, 27, 33, 38, 4, 6, 7, 8, 25, 7, 28, 30, 35, 39, 20, 27, 31, 38, 41, 18, 27, 35, 37, 38, 17, 30, 32, 38, 39, 11, 12, 24, 33, 36, 1, 3, 8, 25, 34, 2, 3, 7, 15, 35, 8, 18, 19, 27, 32, 1, 3, 11, 15, 26, 15, 17, 21, 29, 36, 4, 16, 22, 24, 25, 3, 4, 19, 31, 35, 1, 15, 26, 33, 35, 8, 15, 29, 39, 40, 14, 19, 27, 32, 34, 8, 12, 22, 23, 28, 13, 28, 29, 31, 40, 1, 4, 16, 18, 26, 5, 8, 25, 31, 39, 5, 8, 16, 32, 33, 6, 11, 15, 21, 37, 19, 27, 32, 36, 37, 3, 10, 16, 25, 34, 5, 12, 18, 23, 37, 1, 11, 20, 30, 37, 11, 16, 29, 31, 39, 4, 13, 23, 28, 39, 9, 15, 25, 28, 32, 1, 7, 18, 20, 25, 8, 9, 25, 28, 33, 4, 10, 22, 26, 33, 4, 8, 9, 11, 27, 13, 21, 26, 30, 41, 1, 15, 24, 33, 39, 8, 11, 27, 34, 41, 12, 13, 14, 25, 34, 14, 16, 21, 31, 39, 4, 17, 18, 27, 37, 5, 10, 11, 15, 32, 6, 14, 27, 35, 36, 4, 14, 28, 34, 38, 1, 11, 14, 22, 30, 4, 5, 8, 23, 33, 3, 6, 14, 19, 32, 2, 19, 20, 23, 34, 3, 4, 14, 18, 29, 7, 10, 26, 37, 41, 12, 15, 19, 26, 34, 9, 15, 26, 27, 36, 2, 5, 22, 27, 34, 2, 13, 14, 21, 26, 8, 22, 23, 29, 37, 2, 18, 23, 24, 36, 3, 13, 19, 26, 37, 15, 17, 18, 24, 41, 5, 8, 12, 13, 34, 4, 9, 13, 28, 39, 6, 13, 21, 28, 29, 1, 7, 17, 29, 38, 11, 18, 25, 31, 39, 1, 2, 18, 26, 33, 10, 14, 16, 17, 34, 13, 15, 28, 29, 30, 2, 10, 12, 13, 41, 11, 13, 26, 27, 32, 3, 4, 30, 33, 40, 1, 7, 15, 19, 26, 4, 5, 14, 18, 34, 3, 5, 6, 33, 40, 10, 20, 23, 25, 39, 11, 13, 21, 36, 41, 18, 22, 30, 33, 36, 1, 7, 10, 12, 17, 9, 15, 23, 32, 38, 6, 8, 32, 33, 40, 14, 21, 31, 32, 36, 11, 23, 24, 33, 34, 8, 13, 17, 20, 36, 10, 16, 27, 30, 33, 1, 3, 4, 6, 23, 2, 4, 22, 32, 38, 2, 15, 18, 19, 21, 2, 4, 5, 20, 21, 21, 22, 29, 38, 40, 10, 27, 28, 32, 37, 5, 6, 8, 37, 40, 2, 9, 11, 40, 41, 10, 11, 17, 28, 34, 13, 15, 17, 18, 37, 9, 14, 21, 34, 35, 20, 22, 26, 33, 37, 3, 16, 18, 28, 31, 3, 24, 31, 33, 37, 1, 27, 28, 38, 40, 4, 20, 25, 33, 40, 7, 23, 25, 27, 32, 5, 6, 7, 13, 28, 3, 7, 17, 30, 36, 9, 18, 20, 37, 40, 1, 14, 21, 27, 37, 7, 18, 22, 23, 34, 10, 12, 25, 26, 40, 4, 9, 32, 34, 38, 2, 13, 16, 24, 33, 4, 18, 25, 30, 40, 7, 10, 27, 28, 33, 13, 16, 21, 27, 29, 10, 21, 32, 34, 35, 6, 16, 17, 22, 27, 16, 21, 24, 40, 41, 1, 2, 5, 9, 37, 1, 10, 17, 19, 37, 11, 20, 21, 30, 36, 1, 5, 22, 26, 30, 9, 12, 25, 34, 38, 2, 3, 6, 18, 28, 3, 6, 20, 22, 26, 3, 4, 9, 24, 27, 4, 7, 29, 32, 36, 4, 11, 18, 37, 40, 13, 15, 23, 34, 41, 17, 18, 34, 35, 36, 2, 14, 26, 33, 38, 1, 4, 22, 23, 32, 6, 13, 19, 33, 39, 8, 11, 12, 29, 40, 1, 4, 9, 11, 16, 5, 6, 13, 15, 28, 3, 10, 18, 19, 40, 1, 15, 25, 28, 38, 4, 19, 23, 26, 28, 1, 5, 11, 12, 36, 3, 14, 19, 23, 38, 1, 5, 9, 11, 35, 6, 10, 19, 23, 30, 14, 16, 23, 35, 40, 3, 5, 10, 15, 35, 4, 28, 33, 38, 41, 2, 17, 20, 22, 30, 7, 19, 20, 26, 31, 11, 13, 16, 17, 25, 3, 10, 16, 28, 39, 9, 18, 29, 37, 40, 2, 3, 25, 34, 41, 11, 28, 33, 38, 40, 4, 5, 9, 23, 41, 2, 9, 10, 22, 41, 1, 4, 9, 20, 27, 4, 7, 17, 24, 27, 3, 14, 15, 24, 29, 9, 13, 15, 27, 37, 17, 19, 26, 30, 34, 12, 16, 19, 21, 41, 1, 16, 24, 29, 39, 8, 21, 23, 25, 32, 2, 3, 22, 24, 40, 13, 15, 17, 28, 33, 1, 6, 19, 38, 41, 7, 17, 18, 21, 26, 3, 8, 21, 30, 35, 2, 24, 29, 33, 38, 7, 17, 18, 31, 36, 24, 31, 33, 38, 39, 21, 24, 27, 35, 41, 5, 9, 17, 23, 40, 17, 22, 29, 32, 34, 13, 14, 25, 36, 39, 2, 10, 22, 30, 32, 2, 16, 23, 28, 38, 5, 27, 30, 36, 41, 8, 23, 26, 29, 38, 6, 11, 22, 37, 38, 9, 26, 30, 35, 36, 10, 19, 29, 32, 40, 6, 11, 26, 27, 40, 1, 16, 21, 30, 33, 13, 21, 22, 33, 34, 5, 13, 23, 26, 37, 2, 11, 21, 24, 37, 4, 5, 20, 31, 34, 1, 20, 22, 27, 33, 1, 6, 11, 12, 14, 5, 10, 11, 36, 40, 5, 15, 36, 38, 39, 3, 6, 9, 17, 28, 13, 21, 24, 26, 37, 6, 10, 14, 17, 37, 5, 18, 23, 36, 38, 11, 13, 28, 36, 38, 5, 8, 17, 29, 41, 2, 12, 14, 27, 39, 4, 11, 20, 21, 39, 2, 6, 14, 31, 38, 2, 25, 26, 32, 33, 4, 10, 26, 32, 37, 5, 13, 14, 32, 41, 1, 4, 20, 21, 27, 2, 7, 14, 32, 34, 9, 12, 23, 24, 29, 9, 19, 22, 30, 33, 7, 13, 19, 35, 41, 1, 18, 19, 21, 24, 15, 18, 29, 31, 33, 14, 15, 16, 29, 35, 5, 16, 21, 33, 36, 12, 17, 23, 32, 34, 17, 20, 23, 33, 40, 5, 9, 24, 30, 34, 9, 14, 21, 26, 28, 1, 7, 19, 21, 24, 1, 5, 22, 33, 37, 1, 5, 17, 23, 29, 3, 11, 17, 24, 30, 7, 12, 18, 22, 34, 5, 7, 13, 21, 38, 9, 24, 32, 40, 41, 3, 17, 26, 33, 38, 5, 6, 7, 14, 30, 8, 19, 20, 28, 30, 4, 15, 26, 29, 32, 5, 7, 25, 28, 35, 10, 23, 35, 37, 41, 3, 11, 17, 19, 41, 4, 24, 25, 29, 34, 8, 22, 25, 27, 33, 2, 16, 20, 30, 31, 14, 19, 20, 33, 35, 15, 16, 17, 20, 38, 14, 23, 28, 29, 34, 7, 21, 26, 29, 36, 8, 9, 10, 25, 30, 12, 17, 26, 28, 36, 6, 10, 11, 20, 40, 7, 8, 21, 40, 41, 9, 15, 23, 33, 36, 1, 9, 27, 35, 36, 9, 13, 17, 18, 41, 12, 13, 24, 25, 29, 16, 21, 23, 36, 39, 6, 9, 19, 26, 28, 11, 27, 30, 35, 37, 3, 6, 23, 34, 38, 9, 14, 19, 24, 35, 5, 6, 20, 33, 41, 9, 13, 33, 37, 38, 9, 13, 24, 25, 36, 11, 15, 20, 36, 38, 6, 19, 24, 25, 37, 8, 12, 27, 33, 34, 9, 12, 18, 28, 36, 12, 17, 29, 34, 40, 1, 2, 10, 24, 34, 7, 25, 31, 36, 39, 1, 6, 7, 21, 28, 4, 5, 6, 18, 39, 22, 24, 26, 29, 36, 12, 23, 30, 31, 39, 28, 34, 35, 37, 38, 4, 8, 11, 22, 25, 5, 10, 23, 33, 40, 9, 19, 21, 34, 38, 6, 8, 9, 19, 35, 16, 32, 33, 34, 37, 1, 3, 6, 12, 15, 4, 29, 30, 39, 40, 16, 21, 24, 32, 36, 8, 19, 25, 30, 34, 10, 18, 24, 25, 39, 20, 24, 27, 28, 38, 12, 16, 18, 20, 31, 1, 11, 13, 19, 36, 20, 22, 25, 34, 38, 2, 10, 17, 27, 35, 4, 6, 8, 26, 40, 9, 12, 21, 28, 30, 19, 21, 26, 28, 37, 2, 4, 5, 32, 36, 15, 22, 25, 31, 41, 7, 13, 16, 29, 39, 10, 21, 23, 25, 37, 18, 22, 30, 35, 38, 10, 12, 13, 18, 39, 14, 17, 20, 30, 36, 21, 24, 25, 29, 35, 4, 7, 22, 33, 36, 3, 7, 10, 23, 37, 8, 9, 14, 25, 31, 7, 11, 30, 38, 40, 12, 13, 18, 26, 40, 2, 12, 22, 26, 36, 2, 19, 20, 23, 24, 1, 5, 16, 17, 27, 8, 17, 22, 35, 38, 1, 3, 19, 36, 38, 1, 12, 29, 35, 38, 2, 3, 27, 39, 41, 7, 11, 26, 35, 36, 14, 16, 18, 31, 35, 17, 24, 35, 38, 41, 3, 11, 27, 31, 37, 3, 25, 26, 29, 32, 8, 17, 19, 30, 33, 3, 18, 28, 31, 32, 1, 9, 13, 25, 36, 4, 6, 8, 17, 29, 7, 11, 24, 32, 33, 2, 7, 20, 26, 41, 5, 7, 14, 28, 38, 3, 8, 9, 21, 26, 5, 11, 25, 40, 41, 10, 13, 14, 29, 34, 3, 5, 15, 31, 37, 16, 24, 27, 31, 34, 4, 13, 16, 27, 40, 24, 26, 27, 32, 39, 10, 11, 12, 15, 23, 15, 31, 34, 36, 38, 5, 9, 21, 29, 35, 9, 13, 17, 22, 40, 13, 22, 28, 36, 39, 5, 16, 17, 19, 30, 13, 18, 25, 26, 38, 1, 5, 9, 27, 28, 3, 5, 19, 37, 39, 10, 13, 24, 32, 40, 3, 7, 8, 17, 24, 1, 10, 11, 12, 20, 4, 11, 15, 19, 23, 17, 26, 30, 38, 39, 6, 7, 10, 31, 41, 18, 21, 24, 32, 39, 4, 8, 12, 17, 24, 3, 4, 7, 23, 38, 11, 17, 23, 29, 34, 1, 10, 25, 30, 32, 2, 18, 20, 24, 27, 16, 24, 27, 31, 38, 1, 13, 17, 18, 36, 6, 8, 13, 20, 24, 5, 13, 16, 25, 29, 7, 13, 32, 33, 34, 15, 19, 26, 31, 35, 5, 9, 14, 21, 26, 1, 10, 16, 20, 31, 1, 6, 25, 33, 35, 3, 13, 14, 17, 30, 2, 5, 9, 38, 39, 22, 24, 27, 35, 36, 10, 18, 20, 27, 36, 5, 7, 20, 33, 35, 3, 8, 13, 21, 37, 13, 19, 22, 25, 39, 3, 14, 21, 23, 38, 15, 20, 30, 32, 35, 8, 9, 12, 24, 32, 10, 25, 35, 36, 37, 1, 11, 14, 18, 36, 7, 9, 25, 31, 38, 4, 5, 6, 16, 34, 5, 8, 9, 14, 28, 12, 17, 20, 23, 33, 1, 4, 8, 20, 25, 1, 8, 15, 27, 34, 10, 14, 15, 18, 23, 3, 18, 29, 31, 33, 6, 10, 16, 18, 21, 1, 4, 11, 14, 25, 7, 11, 19, 28, 37, 8, 13, 22, 28, 33, 10, 11, 14, 20, 37, 13, 15, 17, 19, 36, 10, 22, 26, 33, 36, 10, 15, 18, 19, 35, 8, 9, 20, 31, 33, 3, 8, 18, 31, 34, 2, 14, 24, 27, 31, 9, 11, 12, 15, 22, 13, 14, 15, 37, 39, 3, 4, 7, 27, 34, 6, 14, 24, 30, 38, 2, 3, 19, 21, 30, 5, 6, 15, 31, 32, 1, 6, 24, 26, 30, 9, 11, 25, 29, 30, 1, 16, 22, 30, 34, 1, 2, 12, 19, 34, 4, 10, 13, 20, 31, 18, 28, 33, 35, 39, 22, 23, 25, 27, 36, 1, 7, 28, 33, 34, 1, 12, 14, 32, 39, 16, 25, 28, 30, 32, 12, 19, 28, 31, 39, 12, 19, 25, 27, 32, 8, 14, 20, 31, 38, 10, 19, 21, 23, 32, 2, 3, 24, 30, 36, 3, 11, 22, 26, 39, 4, 13, 29, 33, 37, 9, 22, 30, 36, 39, 2, 8, 9, 33, 34, 2, 5, 15, 23, 28, 11, 23, 26, 29, 31, 10, 13, 15, 29, 34, 13, 18, 21, 22, 32, 4, 5, 7, 20, 24, 1, 15, 17, 29, 38, 2, 7, 20, 35, 38, 26, 33, 36, 37, 38, 3, 5, 14, 24, 39, 7, 8, 9, 24, 28, 8, 18, 29, 36, 37, 7, 10, 21, 25, 29, 3, 8, 26, 35, 36, 1, 21, 22, 24, 36, 5, 7, 19, 33, 37, 8, 22, 29, 30, 37, 5, 7, 14, 17, 25, 11, 22, 26, 33, 38, 7, 19, 20, 27, 34, 11, 18, 19, 30, 37, 5, 11, 14, 34, 38, 6, 9, 23, 29, 39, 2, 16, 22, 24, 37, 1, 8, 9, 29, 35, 15, 18, 20, 23, 28, 10, 14, 26, 30, 37, 3, 4, 6, 30, 36, 2, 5, 8, 18, 27, 5, 9, 21, 35, 37, 6, 8, 14, 22, 38, 21, 22, 27, 29, 37, 3, 4, 11, 34, 38, 7, 12, 17, 21, 32, 4, 8, 15, 26, 38, 6, 8, 23, 33, 35, 7, 19, 27, 37, 39, 4, 10, 24, 25, 38, 3, 5, 21, 36, 37, 6, 20, 27, 30, 34, 10, 14, 19, 21, 29, 13, 15, 30, 36, 37, 2, 15, 17, 31, 32, 8, 17, 34, 36, 37, 1, 11, 26, 29, 35, 10, 16, 17, 35, 36, 3, 17, 22, 29, 32, 7, 9, 10, 18, 38, 1, 5, 15, 18, 24, 9, 11, 12, 14, 35, 7, 10, 28, 29, 34, 10, 21, 24, 26, 38, 7, 22, 26, 34, 39, 1, 8, 10, 25, 31, 2, 3, 9, 18, 28, 5, 10, 24, 32, 33, 2, 8, 13, 14, 37, 3, 11, 15, 33, 35, 11, 17, 23, 24, 28, 10, 14, 20, 35, 37, 1, 19, 24, 26, 38, 20, 30, 32, 36, 39, 6, 24, 28, 35, 38, 3, 9, 10, 19, 28, 18, 22, 25, 31, 33, 3, 6, 8, 20, 21, 7, 16, 19, 21, 39, 10, 19, 27, 31, 36, 13, 21, 26, 29, 37, 14, 15, 21, 24, 25, 5, 10, 17, 21, 29, 3, 12, 25, 26, 32, 12, 14, 21, 34, 36, 5, 9, 14, 15, 38, 2, 27, 28, 30, 39, 5, 9, 11, 18, 38, 7, 15, 27, 30, 38, 13, 20, 24, 27, 35, 14, 15, 19, 20, 22, 4, 10, 13, 16, 19, 1, 2, 16, 35, 38, 6, 10, 20, 27, 34, 5, 6, 11, 21, 34, 6, 15, 28, 30, 36, 2, 5, 26, 28, 33, 14, 19, 21, 23, 33, 9, 10, 20, 22, 30, 1, 2, 13, 29, 34, 1, 6, 13, 17, 18, 3, 8, 11, 21, 28, 4, 7, 10, 16, 22, 3, 5, 6, 15, 22, 22, 24, 32, 35, 38, 14, 18, 26, 27, 28, 14, 20, 24, 26, 35, 4, 24, 26, 33, 37, 2, 14, 16, 25, 29, 1, 3, 24, 26, 36, 8, 20, 30, 31, 36, 6, 9, 17, 24, 35, 14, 18, 27, 35, 39, 5, 15, 19, 37, 38, 4, 6, 11, 18, 26, 18, 21, 22, 26, 32, 3, 7, 19, 20, 21, 3, 5, 16, 21, 33, 6, 14, 20, 22, 35, 6, 11, 13, 25, 28, 8, 13, 16, 38, 39, 19, 20, 24, 27, 29, 5, 14, 22, 31, 38, 18, 20, 22, 32, 36, 16, 19, 25, 34, 39, 4, 16, 19, 33, 38, 19, 22, 29, 33, 39, 11, 22, 26, 30, 32, 5, 6, 25, 27, 36, 5, 20, 32, 37, 38, 6, 13, 31, 35, 39, 2, 6, 22, 37, 39, 8, 22, 27, 34, 35, 3, 10, 21, 24, 29, 7, 21, 24, 30, 35, 14, 16, 21, 36, 38, 5, 10, 25, 30, 33, 3, 5, 9, 17, 23, 2, 8, 26, 34, 38, 1, 7, 23, 31, 38, 1, 10, 16, 22, 38, 5, 8, 9, 18, 27, 7, 13, 22, 25, 34, 4, 6, 11, 30, 33, 16, 19, 20, 21, 39, 11, 19, 21, 31, 36, 2, 3, 6, 12, 24, 3, 12, 16, 20, 37, 11, 18, 27, 33, 39, 7, 21, 24, 27, 30, 15, 16, 18, 21, 31, 5, 10, 22, 25, 26, 11, 16, 18, 29, 35, 1, 9, 25, 31, 32, 6, 7, 10, 23, 31, 5, 22, 28, 29, 37, 15, 18, 19, 24, 39, 4, 9, 12, 25, 32, 5, 7, 30, 31, 37, 2, 4, 9, 31, 39, 8, 10, 15, 31, 39, 2, 9, 22, 24, 30, 6, 11, 21, 28, 29, 14, 19, 20, 32, 33, 12, 13, 15, 20, 33, 1, 2, 19, 22, 37, 2, 12, 30, 36, 39, 2, 3, 5, 7, 28, 2, 25, 28, 32, 33, 8, 16, 19, 25, 28, 19, 30, 31, 36, 39, 4, 12, 23, 26, 36, 10, 11, 21, 27, 29, 1, 2, 5, 8, 26, 1, 12, 16, 18, 25, 15, 20, 21, 24, 34, 7, 12, 19, 31, 32, 12, 17, 19, 26, 32, 9, 18, 23, 29, 36, 12, 16, 30, 37, 38, 1, 11, 18, 28, 31, 17, 23, 28, 31, 35, 7, 18, 23, 32, 33, 4, 13, 15, 35, 37, 3, 22, 24, 30, 34, 7, 9, 28, 30, 37, 5, 12, 24, 34, 39, 2, 4, 9, 10, 11, 1, 8, 15, 18, 20, 12, 15, 22, 23, 34, 6, 8, 14, 32, 33, 1, 7, 15, 22, 24, 9, 15, 16, 18, 38, 13, 17, 22, 28, 31, 12, 19, 22, 34, 35, 2, 7, 10, 15, 34, 13, 22, 25, 31, 37, 1, 16, 27, 30, 31, 12, 24, 28, 30, 32, 14, 17, 21, 30, 38, 2, 6, 12, 17, 27, 1, 2, 8, 18, 39, 6, 10, 12, 21, 28, 10, 20, 22, 29, 31, 1, 5, 12, 22, 23, 5, 7, 8, 21, 26, 4, 9, 14, 21, 24, 6, 31, 32, 34, 39, 7, 17, 24, 33, 34, 3, 16, 22, 24, 36, 1, 12, 20, 31, 35, 1, 2, 28, 34, 38, 5, 21, 27, 30, 36, 8, 10, 14, 31, 32, 1, 3, 16, 26, 35, 2, 4, 26, 30, 35, 2, 6, 24, 31, 36, 5, 11, 12, 15, 37, 2, 15, 16, 17, 20, 8, 10, 16, 38, 39, 2, 12, 14, 16, 39, 15, 17, 27, 31, 38, 1, 3, 16, 32, 35, 6, 14, 16, 23, 30, 12, 22, 31, 34, 37, 3, 10, 12, 22, 39, 4, 20, 28, 38, 39, 2, 7, 18, 35, 38, 6, 7, 10, 16, 31, 2, 7, 13, 34, 38, 17, 18, 24, 26, 29, 11, 17, 21, 26, 35, 2, 3, 12, 29, 31, 13, 15, 20, 25, 38, 15, 22, 30, 34, 39, 18, 22, 35, 37, 39, 3, 13, 14, 35, 37, 1, 5, 30, 31, 32, 6, 7, 12, 28, 34, 1, 3, 16, 23, 32, 1, 7, 8, 13, 22, 1, 4, 11, 20, 36, 6, 14, 27, 28, 29, 11, 14, 24, 25, 38, 1, 12, 26, 28, 29, 1, 6, 8, 22, 37, 5, 11, 22, 35, 37, 3, 7, 11, 15, 34, 4, 7, 22, 31, 33, 2, 7, 11, 19, 29, 18, 19, 21, 22, 25, 13, 17, 18, 19, 34, 1, 20, 24, 30, 38, 11, 13, 14, 35, 36, 3, 11, 28, 31, 34, 2, 6, 11, 27, 36, 1, 9, 11, 16, 25, 15, 16, 20, 26, 38, 4, 6, 31, 34, 36, 8, 14, 19, 23, 31, 11, 22, 23, 28, 39, 2, 16, 19, 36, 38, 8, 12, 33, 36, 37, 3, 11, 21, 30, 39, 3, 8, 9, 14, 29, 7, 9, 20, 21, 37, 8, 13, 14, 30, 35, 3, 11, 26, 37, 38, 2, 8, 15, 33, 34, 2, 9, 14, 17, 26, 2, 6, 15, 34, 35, 1, 7, 23, 24, 37, 5, 7, 10, 26, 30, 8, 10, 11, 22, 33, 5, 8, 20, 30, 33, 11, 15, 21, 28, 39, 15, 16, 17, 32, 33, 17, 23, 28, 29, 39, 4, 7, 14, 18, 39, 8, 17, 27, 35, 37, 5, 7, 18, 21, 37, 4, 17, 18, 25, 31, 20, 26, 28, 31, 35, 5, 11, 14, 19, 23, 4, 7, 17, 27, 30, 6, 26, 27, 33, 35, 22, 25, 35, 36, 38, 4, 13, 15, 23, 26, 7, 9, 28, 32, 39, 14, 22, 25, 35, 37, 10, 23, 25, 35, 38, 5, 16, 17, 20, 21, 6, 10, 27, 28, 35, 2, 9, 20, 31, 37, 1, 19, 26, 31, 36, 3, 12, 24, 27, 29, 10, 17, 18, 31, 37, 3, 13, 17, 26, 32, 2, 7, 19, 25, 31, 2, 8, 19, 23, 27, 9, 16, 28, 34, 35, 1, 12, 33, 35, 39, 11, 15, 24, 32, 36, 4, 8, 12, 13, 35, 8, 14, 18, 22, 28, 1, 20, 22, 31, 32, 2, 8, 16, 17, 35, 1, 10, 16, 20, 25, 6, 18, 23, 33, 38, 5, 10, 21, 22, 30, 13, 17, 18, 19, 35, 4, 10, 12, 20, 37, 20, 22, 24, 26, 32, 18, 26, 28, 30, 36, 1, 2, 21, 25, 33, 3, 4, 9, 16, 35, 5, 12, 14, 28, 29, 2, 10, 17, 21, 38, 1, 9, 11, 28, 34, 2, 33, 35, 37, 38, 2, 6, 10, 35, 38, 4, 13, 16, 19, 35, 4, 7, 9, 12, 15, 4, 7, 21, 30, 32, 6, 13, 22, 30, 32, 2, 9, 13, 18, 33, 3, 10, 29, 37, 38, 1, 13, 23, 27, 32, 14, 15, 17, 24, 27, 8, 10, 14, 26, 31, 5, 15, 17, 31, 35, 12, 27, 31, 33, 36, 9, 12, 13, 15, 38, 13, 16, 27, 29, 32, 8, 14, 20, 24, 26, 12, 19, 23, 24, 33, 2, 9, 14, 16, 19, 9, 24, 31, 38, 39, 13, 22, 25, 26, 35, 10, 14, 17, 24, 36, 8, 11, 16, 17, 32, 1, 11, 27, 28, 31, 15, 23, 34, 35, 36, 1, 7, 14, 17, 35, 1, 24, 36, 37, 39, 9, 13, 16, 23, 36, 12, 13, 23, 24, 37, 1, 7, 13, 31, 33, 8, 12, 16, 27, 28, 6, 13, 28, 29, 30, 9, 10, 22, 23, 39, 1, 3, 5, 27, 35, 6, 13, 16, 34, 39, 14, 23, 25, 34, 37, 9, 17, 18, 36, 37, 11, 16, 24, 30, 36, 9, 19, 22, 26, 34, 11, 20, 22, 26, 29, 5, 24, 28, 29, 32, 10, 23, 25, 30, 33, 6, 8, 22, 31, 33, 1, 8, 10, 23, 38, 5, 9, 12, 32, 33, 5, 29, 31, 33, 35, 1, 4, 19, 23, 37, 24, 29, 30, 32, 36, 5, 12, 13, 23, 33, 1, 17, 18, 25, 26, 6, 9, 20, 33, 39, 3, 25, 30, 34, 39, 1, 5, 11, 14, 26, 4, 12, 13, 31, 35, 19, 20, 23, 24, 36, 1, 2, 6, 24, 34, 15, 32, 35, 36, 37, 1, 8, 14, 25, 38, 5, 8, 21, 23, 34, 1, 4, 10, 34, 39, 6, 7, 24, 36, 37, 6, 8, 22, 26, 38, 11, 17, 24, 27, 35, 12, 13, 16, 21, 29, 17, 18, 19, 28, 38, 23, 25, 31, 32, 39, 22, 24, 30, 31, 37, 3, 17, 21, 27, 31, 4, 24, 27, 28, 33, 13, 16, 26, 27, 31, 6, 22, 24, 34, 39, 20, 27, 30, 35, 37, 1, 4, 7, 15, 26, 8, 14, 16, 32, 34, 5, 23, 27, 37, 38, 4, 7, 20, 29, 35, 2, 11, 18, 25, 36, 2, 4, 5, 6, 10, 8, 11, 21, 25, 31, 5, 12, 23, 24, 27, 16, 18, 19, 28, 39, 1, 11, 13, 18, 39, 4, 10, 12, 28, 30, 9, 13, 25, 26, 30, 9, 11, 16, 20, 38, 4, 7, 18, 33, 39, 4, 11, 17, 31, 37, 15, 31, 34, 36, 38, 9, 11, 29, 34, 37, 4, 12, 21, 23, 31, 11, 12, 13, 31, 38, 12, 18, 31, 33, 39, 5, 9, 14, 16, 30, 7, 9, 11, 17, 30, 2, 5, 7, 14, 22, 22, 24, 28, 29, 31, 1, 10, 20, 21, 32, 12, 29, 31, 32, 33, 8, 13, 20, 30, 33, 5, 6, 13, 23, 28, 6, 7, 18, 22, 25, 14, 18, 19, 22, 35, 4, 9, 11, 26, 31, 1, 21, 23, 24, 36, 12, 25, 26, 29, 34, 3, 11, 13, 20, 26, 12, 14, 23, 26, 33, 13, 22, 24, 29, 37, 1, 16, 17, 22, 29, 2, 12, 17, 32, 34, 2, 10, 21, 25, 29, 8, 25, 26, 34, 39, 2, 28, 31, 33, 34, 7, 11, 17, 18, 21, 3, 6, 8, 12, 37, 8, 10, 14, 17, 35, 20, 21, 25, 26, 38, 15, 19, 22, 23, 37, 9, 12, 15, 20, 25, 6, 9, 18, 23, 31, 19, 20, 27, 36, 38, 1, 5, 12, 28, 37, 1, 3, 6, 24, 25, 14, 23, 26, 32, 39, 8, 24, 29, 35, 36, 18, 21, 32, 36, 37)
V = Counter(Value)
print(V)
#For 'x' amount of number sets (from spreadsheet).
#List Size(Ex. 917) do 917x5
myInt = 4585
#Divide for percentage
percentdiv = [x / myInt for x in Value]
#Times new value by 100 and format 2 decimal places to get percentage
for i in percentdiv:
Percentage = ("%{:.2f}".format(i * 100))
for x in Value:
print (x, Percentage,)
I'm trying to figure out how to get python3 to print something like:
1 = %0.34, 2 = %0.21, 3 = %0.03
4 = %0.22, 5 = %0.13, 6 = %0.01
But for some reason I get:
1 %0.07
3 %0.07
8 %0.07
25 %0.07
34 %0.07
2 %0.07
3 %0.07
7 %0.07
15 %0.07
35 %0.07
8 %0.07
18 %0.07
19 %0.07
27 %0.07
32 %0.07
1 %0.07
I noticed too that the numbers were looping themselves.
I like what Counter does I like the formatting, but I need the percentage not just the number of times. Can someone help, please?
I think you need the percentage of each value's count in the Value list.Please correct if I am wrong,
for x,i in zip(Value,percentdiv):
print("{}={:.2f}".format(x,i*100),end='')
By default print function have the \n in a end so it should be,
import sys
for i in percentdiv:
Percentage = ("%{:.2f}".format(i * 100))
for x in Value:
sys.stdout.write(x, Percentage,)
sys.stdout.write("\n")
From here code copied

Categories