I have a dataframe with missing data in several columns. In some of these columns, say ‘Col_A’ to ‘Col_D’, I’d like to replace them with 0. I tried it this way: but I got the error message <lambda>() takes 1 positional argument but 2 were given. Eventually, I changed my sol…
Tag: pandas
Simple calculation on table. Please help me to make my code more effective
Please help me to make my code more effective. This is my df: Please help me to find the Vshale. Vshale on each well = GR – GR(min) / GR(max) – GR(min). This is my desired result: This code is work for me, but, I should create a new column that consists of GRMax and GRMin and merge it into
Is it possible to create an additional pct_change column for each column of the dataframe?
I tried to solve this on my own and have searched other topics for help, yet, my problem remains. If anyone can help me or point me to the right direction I would appreciate I’m fairly new to python and I’m trying to perform some changes on a pandas dataframe. To summarize, I want to verify percen…
Is there a possibility in python to output column values as file names?
I have the following df: Now I want to output column A values as file names. My output now is: 0.xml, 1.xml, 2.xml. However I would like my output files to be the following: 1.xml, 1.xml, 4.xml. Can you help me? Answer Use the ‘A’ value from the row, so:
Binding a dataframe to a variable in a for-loop converts it into a tuple?
Sorry if this is basic but I am new to python. I was experimenting with creating plots in pandas through a for loop when I got AttributeError: ‘tuple’ object has no attribute ‘plot’. Looking at my code, I found out that assigning a dataframe to a variable converts it into a tuple. See …
Allow two datetime format using raise ValueError python
I have two csv files with two different format which are ‘%m/%d/%Y %H:%M:%S’ and ‘%d/%m/%Y %H:%M:%S’. Hence, I will get such ValueError : Sample data from file1.csv where month is in the middle: While file2.csv, month is at front : The column comes as String then I require to transform…
Pickle data not loading
Here I the data I try to save as a “pickle file” Then in a separate script i open it: It seems to run smoothly, however the only thing that appears in my variable explorer is a Buffered Reader Object. Answer pkl.load returns the loaded object. Your code immediately discards it. You should assign i…
Converting each row into a dataframe and concatenate results
I have a dataframe df in the format below, where content is a string column. and I want to convert it to the format: I tried doing this, which works, but it doesn’t look nice. Is there any better way to do this? Answer Let us try
Fill np.nan with values based on other columns
I try to match the offer_id to the corresponding transaction. This is the dataset: The rule is that when the offer is viewed, the transaction belongs to this offer id. If the offer is reveived, but not viewed, the transaction does not belong to the offer id. I hope the time variable makes it clear. This is th…
How to convert a pandas dataframe column to an image array i.e. a numpy array with shape (n,n) in Python?
Suppose my dataframe has 750 rows in a column and I want to convert that column to an image array of (20,20) numpy array. How to do that? EDIT1: I want to use the array for ax.contourf (x,y,z) as z. I got x,y by doing x,y=np.meshgrid(df3.x,df.y) now I want to convert another column to an (n,n) array to vary t…