Re: How to plot a data including date and time?
On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com wrote: > I have a .csv file, in first column I have date and hour, and in the second > column I have energy use data. How can I make a bar chart with Date and time > as the x axis and the energy use as the Y axis? > > Thanks Thank you for your guidance. I am already using matplotlib but I do not know how to import a column of date and time and to use it properly as the x axis. can you tell me the code? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
MRAB wrote: Another thing you might want to avoid is naming something with what it is, e.g. "Trails_Table" (why not just "Trails"). Or possibly just "Trail", since any table potentially contains multiple rows, so making all your table names plural doesn't add any information. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
On Wed, Aug 14, 2019 at 9:06 PM Gregory Ewing wrote: > > MRAB wrote: > > Another thing you might want to avoid is naming something with what it > > is, e.g. "Trails_Table" (why not just "Trails"). > > Or possibly just "Trail", since any table potentially contains > multiple rows, so making all your table names plural doesn't > add any information. > I prefer to say "Trails" for the table, and "Trail" would then refer to a single row from that table. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
On Wed, 14 Aug 2019, Chris Angelico wrote: I prefer to say "Trails" for the table, and "Trail" would then refer to a single row from that table. +1 Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: How to plot a data including date and time?
On 14 Aug 2019, amirrezaheidary...@gmail.com wrote (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>): > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com > wrote: > > I have a .csv file, in first column I have date and hour, and in the second > > column I have energy use data. How can I make a bar chart with Date and > > time as the x axis and the energy use as the Y axis? > > > > Thanks > > Thank you for your guidance. I am already using matplotlib but I do not know > how to import a column of date and time and to use it properly as the x axis. > can you tell me the code? > > Thanks If you don't mind using a steam hammer to crack a nut, it is amazing what you can do with pandas using just the "10 minute guide" chapter in the (shudder) 10,000 page manual. The chief benefit is how thoroughly it protects you from Numpy and Matplotlib. I solved a similar problem (tracking home blood pressure with exponentially weighted means) up and running in half a day from a completely cold start. The graphing bit is a delight. However, if you want to do something that the 10 minute guide does not cover, you can lose a man-month without really trying. Pandas is a beautiful monster! Here's the relevant bit import numpy as np import pandas as pd import matplotlib.pyplot as plt import pytz from pytz import common_timezones, all_timezones #preparing the csv from a text file elided as irrelevant #except that the .csv headings have to be Date Systolic Diastolic for this to work as designed # Plot the intermediate file with pandas after adding exponentially weighted means df = pd.read_csv('Blood pressure.csv') df['Date'] = pd.to_datetime(df['Date']) df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() plt.ioff() df.plot(x='Date') print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more healthy levels plt.ylabel('mm Hg') plt.suptitle("Home BP record") plt.show() That should give you a start -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 -- https://mail.python.org/mailman/listinfo/python-list
Re: How to plot a data including date and time?
On 14 Aug 2019, Elliott Roper wrote (in article<0001hw.23044901039e772c7ca97...@news.giganews.com>): > On 14 Aug 2019, amirrezaheidary...@gmail.com wrote > (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>): > > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com > > wrote: Oh Damn! Here is an attempt to stop the code running into a single line.. > > > > > I have a .csv file, in first column I have date and hour, and in the > > > second > > > column I have energy use data. How can I make a bar chart with Date and > > > time as the x axis and the energy use as the Y axis? > > > > > > Thanks > > > > Thank you for your guidance. I am already using matplotlib but I do not know > > how to import a column of date and time and to use it properly as the x > > axis. > > can you tell me the code? > > > > Thanks > > If you don't mind using a steam hammer to crack a nut, it is amazing what you > can do with pandas using just the "10 minute guide" chapter in the (shudder) > 10,000 page manual. The chief benefit is how thoroughly it protects you from > Numpy and Matplotlib. > I solved a similar problem (tracking home blood pressure with exponentially > weighted means) up and running in half a day from a completely cold start. > The graphing bit is a delight. However, if you want to do something that the > 10 minute guide does not cover, you can lose a man-month without really > trying. Pandas is a beautiful monster! > > Here's the relevant bit > > import numpy as np > > import pandas as pd > > import matplotlib.pyplot as plt > > > #preparing the csv from a text file elided as irrelevant > > #except that the .csv headings have to be Date Systolic Diastolic for this to > work as designed > > # Plot the intermediate file with pandas after adding exponentially weighted > means > > df = pd.read_csv('Blood pressure.csv') > > df['Date'] = pd.to_datetime(df['Date']) > > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() > > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() > > plt.ioff() > > df.plot(x='Date') > > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more > healthy levels > > plt.ylabel('mm Hg') > > plt.suptitle("Home BP record") > > plt.show() > > That should give you a start -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 -- https://mail.python.org/mailman/listinfo/python-list
Re: How to plot a data including date and time?
Elliott Roper ezt írta (időpont: 2019. aug. 14., Sze 15:56): > On 14 Aug 2019, Elliott Roper wrote > (in article<0001hw.23044901039e772c7ca97...@news.giganews.com>): > > > On 14 Aug 2019, amirrezaheidary...@gmail.com wrote > > (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>): > > > > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, > amirrezah...@gmail.com > > > wrote: > > Oh Damn! Here is an attempt to stop the code running into a single line.. > > > > > > > I have a .csv file, in first column I have date and hour, and in the > second > > > > column I have energy use data. How can I make a bar chart with Date > and > > > > time as the x axis and the energy use as the Y axis? > > > > > > > > Thanks > > > > > > Thank you for your guidance. I am already using matplotlib but I do > not know > > > how to import a column of date and time and to use it properly as the x > > > axis. > > > can you tell me the code? > > > > > > Thanks > > > > > If you don't mind using a steam hammer to crack a nut, it is amazing > what you > > can do with pandas using just the "10 minute guide" chapter in the > (shudder) > > 10,000 page manual. The chief benefit is how thoroughly it protects you > from > > Numpy and Matplotlib. > > I solved a similar problem (tracking home blood pressure with > exponentially > > weighted means) up and running in half a day from a completely cold > start. > > The graphing bit is a delight. However, if you want to do something that > the > > 10 minute guide does not cover, you can lose a man-month without really > > trying. Pandas is a beautiful monster! > > > > Here's the relevant bit > > > > import numpy as np > > > > import pandas as pd > > > > import matplotlib.pyplot as plt > > > > > > #preparing the csv from a text file elided as irrelevant > > > > #except that the .csv headings have to be Date Systolic Diastolic for > this to > > work as designed > > > > # Plot the intermediate file with pandas after adding exponentially > weighted > > means > > > > df = pd.read_csv('Blood pressure.csv') > > > > df['Date'] = pd.to_datetime(df['Date']) > > > > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean() > > > > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean() > > > > plt.ioff() > > > > df.plot(x='Date') > > > > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more > > healthy levels > > > > plt.ylabel('mm Hg') > > > > plt.suptitle("Home BP record") > > > > plt.show() > > > > That should give you a start > > -- > To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 > 3CF7 > 637F 896B C810 E199 7E5C A9E4 8E59 E248 > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, Pygal is a very good and easy to use charting library BR, George > -- https://mail.python.org/mailman/listinfo/python-list
Re: fopen() and open() in cpython
On 8/13/19, Windson Yang wrote: > After my investigation, I found Since Python maintains its own buffer when > read/write files, the build-in python open() function will call the open() > system call instead of calling standard io fopen() for caching. So when we > read/write a file in Python, it would not call fopen(), fopen() only use > for Python itself but not for python user. Am I correct? Python 2 I/O wraps C FILE streams (i.e. fopen, fclose, fread, fwrite, fgets). Python 3 has its own I/O stack (raw, buffered, text) that aims to be more reliably cross-platform than C FILE streams. Python 3 still uses FILE streams internally in some cases (e.g. to read pyvenv.cfg at startup). FYI in Windows open() or _wopen() is a C runtime library function, not a system function. It calls the Windows API function CreateFile, which calls the NT system function, NtCreateFile. It's similarly layered for all calls, e.g. read() calls ReadFile or ReadConsoleW, which calls NtReadFile or NtDeviceIoControlFile (ReadConsoleW). -- https://mail.python.org/mailman/listinfo/python-list
In following subplot I have to change the first plot into a bar plot. But using plt.bar rather than plt.plot gives a white plot !
plt.Figure() plt.subplots_adjust(top=0.945, bottom=0.05, left=0.04, right=0.985, hspace=0.67, wspace=0.345) plt.subplot(6,1,1) plt.plot(Date,Energy, "r") plt.title("Hourly hot water energy use") plt.ylabel("kWh") plt.margins(x=0) plt.subplot(6,1,2) plt.plot(Date,Tin) plt.title("Indoor air temperature") plt.ylabel("Celsius") plt.margins(x=0) plt.subplot(6,1,3) plt.plot(Date,RHin, "g") plt.title("Indoor air relative humidity") plt.ylabel("%") plt.margins(x=0) plt.subplot(6,1,4) plt.plot(Date,Tamb, "darkblue") plt.title("Ambient air temperature") plt.ylabel("Celsius") plt.margins(x=0) plt.subplot(6,1,5) plt.plot(Date,Insol, "gold") plt.title("Solar insolation") plt.ylabel("$W/m^2$") plt.margins(x=0) plt.subplot(6,1,6) plt.plot(Date,Wind, "darkslategrey") plt.title("Wind speed") plt.ylabel("$m/s$") plt.margins(x=0) plt.show() -- https://mail.python.org/mailman/listinfo/python-list
Re: fopen() and open() in cpython
Thank you so much for the answer, now it makes sense :D eryk sun 于2019年8月15日周四 上午12:27写道: > On 8/13/19, Windson Yang wrote: > > After my investigation, I found Since Python maintains its own buffer > when > > read/write files, the build-in python open() function will call the > open() > > system call instead of calling standard io fopen() for caching. So when > we > > read/write a file in Python, it would not call fopen(), fopen() only use > > for Python itself but not for python user. Am I correct? > > Python 2 I/O wraps C FILE streams (i.e. fopen, fclose, fread, fwrite, > fgets). Python 3 has its own I/O stack (raw, buffered, text) that aims > to be more reliably cross-platform than C FILE streams. Python 3 still > uses FILE streams internally in some cases (e.g. to read pyvenv.cfg at > startup). > > FYI in Windows open() or _wopen() is a C runtime library function, not > a system function. It calls the Windows API function CreateFile, which > calls the NT system function, NtCreateFile. It's similarly layered for > all calls, e.g. read() calls ReadFile or ReadConsoleW, which calls > NtReadFile or NtDeviceIoControlFile (ReadConsoleW). > -- https://mail.python.org/mailman/listinfo/python-list