As far as I know, python list is a dynamic array. So when we reach a certain size, the capacity of that list will be increased automatically. But the problem is, unlike dynamic array of c or c++, even after increasing the capacity of list instance, the location is not being changed. Why is it happening? IR…
Tag: python
how to add a dataframe with another dataframe and updated common values based on a column
my first data frame- second data frame- I want dataframe dataframe Like this (all values of df2 and uncommon values of df1)- I tried like this- but its not working fine……. Can anyone please suggest a better way- Answer Use pd.concat and drop_duplicates:
All permutations of an array in python
I have an array. I want to generate all permutations from that array, including single element, repeated element, change the order, etc. For example, say I have this array: And if I use the itertools module by doing this: Or using loop like this: I only get: But what I want is: The result is all permutations …
Transpose a single column in DF
The table I have The transpose I want to do is single column transpose index name value batchnumber 0 Result 1 255.00 59534 1 Result 2 260.00 59534 2 Result 3 285.00 59534 3 Result 1 255.00 59530 4 Result 2 260.00 59530 5 Result 3 325.00 59530 I tried pivot Answer You can pivot_wider then melt. In this case,
How to convert multiple excel files to CSV utf-8 encoding using python
I have 30+ xlsx files in same directory and using python I would like to convert all files to csv with utf-8 encoding, regardless of whatever encoding is present in the file. I am using python’s magic library to get the file names (below code).For conversion, I tried the code mention by SO user Julian h…
Discord.py Issue
Whenever I run the following code for a discord bot after I type a message so that the bot sends the link to the image I get the error: I am pretty new to coding, so sorry if it’s something super simple! Answer ‘Messageable.send’ was never awaited tells you what went wrong here. The library …
Replace decimals in floating point numbers
Someone on this platform has already helped me with generating the following code: This code ensures that the last decimal is not a 0 or a 9. However, I would like to have no 0’s nor 9’s in all the decimals that are generated (such that it will not be possible to have a number 1.963749 or 3.459007…
pandas convert timestamp in a dynamic way
I have a dataframe which is having the following timestamps. Total of 5600000 rows! Because I am doing the following operation, it throws an error. (TypeError: Timestamp subtraction must have the same timezones or no timezones) Here i know the problem, and it could be solved by (pd.to_datetime(“2016-01-…
With python; Getting index of wrong item of list [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 9 months ago. Improve this question I’m trying to get the indeces of the items of my list but on one item it returns a wr…
how to specify data on pearson correlation heatmap?
I have a pearson correlation heat map coded, but its showing data from my dataframe which i dont need. is there a way to specify which columns i’d like to include? thanks in advance Answer You can filter the dataframe before calculating correlation