I am doing some topic modelling, and I am interested in showing how the average topic weight changes over time. The problem arises when I plot it using matplotlib (version 3.3.4). On the x-axis I would like to have the categorical month_year variable. The problem is that it is not ordered in a sensible way. I have tried, as suggested
Tag: datetime
Add trend line to datetime matplotlib line graph
I have a pandas dataframe df: And I can plot this easily using plt.plot: But now I want to add a trendline. I tried using some answers: How can I draw scatter trend line on matplot? Python-Pandas Which doesn’t work: Then I found the following question and answer: TypeError: ufunc subtract cannot use operands with types dtype(‘<M8[ns]’) and dtype(‘float64’) But
Dividing 24h into working shifts in Python Pandas
I am dealing with dividing a day into working shifts. Let’s have a look at my sample code: I’d like to divide the time into 3 shifts, 00:00 to 08:00 is Shift1, 08:00 to 16:00 will be Shift2 and till 00:00 will be Shift3. What I get is true, but I would like to know if there is any elegant
Add a filter to timeseries pairs
I have a time series plc tag data as below with values in ‘1’ or ‘0’ Using below code I can get the output Output But my requirement is, I only want to query going back 25 hours, so I add a predicate: But this returns the error: Msg 209 Level 16 State 1 Ambiguous column name ‘datetime’. Answer You
Creating a series of Quarters
Let say I have a date Now starting from mydate, I want to create an array of 10 quarters e.g. 2020-Q1, 2020-Q2, … [total 10 values] Is there any direct way to achieve this? In R, this is pretty straightforward, as I can use seq() function to generate the same. Any pointer will be very helpful Answer it doesnt give
Matching datetime column in pandas with another datetime column and return index
I have two DataFrames – df1 and df2. Both of them contain a datetime column, say date1 and date2. I want to match each value of date1 column to date2 and store the index in a new column. I am trying the following code: but this line throws out following error: Can only compare identically-labeled series objects. I also tried
Finding whether there is any overlap between two date periods in DataFrame
I have the following pd.DataFrame that looks like: I want to create a new column received_medidation that states whether or not (boolean) the patient received medication between admission_timestamp and end_period (even if it was for only one second). So, the boolean should state if there is any time between admission_timestamp and end_period that overlaps with the time between start_med and
ModuleNotFoundError: No module named ‘_ctypes’ while installing libraries
I have not found any useful answers elsewhere, so I want to ask for help here. I’m trying to set up a VPS and I need some libraries (like datetime and random), however, when I type pip3.10 install datetime, it just gives me a bunch of errors: What should I do? Answer As it seems, you are trying to install
Sort the list of tuples in python
I have tuples like this these are the coins and its expiries. The date is in string format, so the arrangement is wrong. so i have changed the format to date and tried to arrange. I have tried the below code. and the result is as expected as sorted. now when i want back in older format which i mentioned
How can I display dates on the x axis in matplotlib?
I have daily data from 1994 Jan 1st – 2000 April 30th. I have the dates in datetime format, but when I plot a line plot with time on the x axis and the variable on the y axis, matplotlib prints out way too much on the x axis. How do I fix this issue with plotting dates? I have