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 below: Output: This doesn’t happen if I
Tag: dataframe
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 to only extract out the date. This is the code
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
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 the
How can I make a new Column “Week” into a dataframe in pandas?
My code is as follows: How can I add “Week” column and values like “2020-01”, “2020-02”? “2020-01” means the first week of 2020. Answer Get the year using dt year attribute and concatenate with week attribute. zfill is to fill leading zeros.
How to convert dataframe into dictionary of sets?
I have a dataframe and want to convert a dictionary consists of set. To be specific, my dataframe and what I want to make it as below: My goal: I also wrote a code below, however, I am not sure it is suitable. In reality, the data is large, so I would like to know any tips or other efficient
Amount of months calculation in DataFrame in Python Pandas?
I have DataFrame like below: And I need to calculate number of MONTHS from Date column until today. Below I upload result which I need: Answer You can modify this solution for subtract by scalar d:
Pandas to lookup and return corresponding values from many dataframes
A list of names and I want to retrieve each of the correspondent information in different data frames, to form a new dataframe. I converted the list into a 1 column dataframe, then to look up its corresponding values in different dataframes. The idea is visualized as: I have tried: But it returns the error message as: I have also
Python skip empty cells
I want to be able to search through my dataframe and skip cells that are blank. However, when i read in the DF it reads the blanks as “nan” DF1 I want to be able to filter through Address1, Street and Town. If there is text inside of those columns I want to add a “|” at the start but
Sort filepaths according to their respective file extensions
I am trying to sort filepaths according to their respective file extensions. I would like to have an output like this: FileType FilePath .h a/b/c/d/xyz.h .h a/b/c/d/xyz1.h .class a/b/c/d/xyz.class .class a/b/c/d/xyz1.class .jar a/b/c/d/xyz.jar .jar a/b/c/d/xyz1.jar But the output I have now is like this: output in excel Below is my code: Could anyone please help me with this. Thanks in