Python Forum
[pandas]How to liner fit time series data and get linear fit equation and r square
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pandas]How to liner fit time series data and get linear fit equation and r square
#1
Hi,
I have below pandas dataframe:

df:
      Time_golden          Golden    is_golden
0   2019 -03-20 10:24:30    98.6     golden
1   2019 -03-20 11:10:30    97.0     golden
2   2019 -03-20 13:13:30    96.0     golden
3   2019 -03-21 13:43:16    95.0     golden
4   2019 -03-23 10:37:11    94.6     golden
5   2019 -03-23 18:43:19    93.0     golden
6   2019 -03-24 22:19:43    92.0     golden
7   2019 -03-25 09:23:45    90.0     golden
8   2019 -03-26 11:42:51    89.0     golden
9   2019 -03-27 20:32:51    87.3     golden
10  2019 -03-27 23:42:51    86.0     golden
11  2019 -03-28 00:52:23    84.0     golden
12  2019 -03-28 03:40:40    82.3     golden
I want to linearly fit and get linear fit equation and r-square. I use below code but it gives an error

xg=df['Time_golden']
yg=df['Golden']
plt.scatter(xg,yg)
ValueError: First argument must be a sequence

Kindly help how to d this,
Reply
#2
Here a test.
So i don't get your error,you may need to update pandas and matplotlib.
Reply
#3
Thanks, and how to add trend line and get equation and Rsquare.
Reply
#4
(Mar-30-2019, 05:08 PM)Sri Wrote: Thanks, and how to add trend line and get equation and Rsquare.
Give it a shot and post back code,also search for those method,i would also need to search for those task.
Reply
#5
Note, you measurements are taken irregularly in time; first three seems to belong the same day, March, 20, but others are distributed over a week (until March, 28). It is likely, that dates were not recognized properly in the previous posts; Look at the following solution.
Reply
#6
Thanks,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Parsing and summing time deltas (duration) onto bar + pie charts using pandas - - DRY Drone4four 2 599 Feb-10-2024, 06:04 PM
Last Post: Drone4four
  Grouping in pandas/multi-index data frame Aleqsie 3 693 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Help: Conversion of Electricity Data into Time Series Data SmallGuy 3 1,240 Oct-04-2023, 03:31 PM
Last Post: deanhystad
  Time Series Production Process Problem Mzarour 1 2,142 Feb-28-2023, 12:25 PM
Last Post: get2sid
  Pandas read csv file in 'date/time' chunks MorganSamage 4 1,717 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
Smile How to further boost the data read write speed using pandas tjk9501 1 1,274 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  reduce time series based on sum condition amdi40 0 1,111 Apr-06-2022, 09:09 AM
Last Post: amdi40
  Chi-square with the contingency table applied to the die Leloup 4 1,992 Mar-16-2022, 12:22 AM
Last Post: jefsummers
  How to accumulate volume of time series amdi40 3 2,325 Feb-15-2022, 02:23 PM
Last Post: amdi40
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,879 Feb-13-2022, 01:19 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020