Skip to content

Tag: python

Issues with CSV file handling (Writing And Reading)

Sup geeks! As a very beginner to CSV files and modules, I am facing some issues while running my codes. At some point, it is acting a bit weird. My objective is to write a program to create a file voter.csv containing voter id, voter name, and voter age. And to read the file and display the number of records.

ValueError: All arrays must be of the same length

can someone help with the error with converting a json file to a data frame pls I’m trying to convert the JSON text file to a data frame but get the array same length error. I have tried double [[]] around the ‘data’ but still doesn’t work. The text file is at https://stackoverflowtez.…

Sorting lists within a list in Python

I have a list J consisting of lists. I am trying to sort elements of each list in ascending order. I present the current and expected outputs. The current output is The expected output is Answer Just remove the range Output:

Line up plots between two separate axis with matplotlib

I have the following plot Which looks as : I would like to arrange the patches on the right plot (ax_dict[‘b’]) so that they’re horizontally aligned with the bars from ax_dict[‘a’]. Currently they’re roughly inline – but the bars are higher / lower on the right than t…

how to detect a braking process in python dataframe

I have some trips, and for each trip contains different steps, the data frame looks like following: I want to know if, on a trip X, the cyclist has braked (speed has decreased by at least 30%). The problem is that the duration between every two steps is each time different. For example, in 6 seconds, the spee…

Rolling N Non-regular Dice in Constant Time

Say I have a non-regular dice defined by probabilities in a list that add up to one, e.g [0.1, 0.3, 0.4, 0.2]. I can use the following code to simulate rolling that dice n times: Counter({3: 4000343, 2: 2998523, 4: 2000309, 1: 1000825}) However, for large n, the code gets quite slow, as choices iterates n tim…