Convert and plot date and time with pandas or numpy - python

Trying to plot date and time using pandas. 'dt' and 'quality'
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
%matplotlib inline
data = pd.read_csv('pontina_FCD.csv')
I've tried lots of options about transfer date, but sill facing the error.

Pandas has methods that support plotting.
Can you try the following:
data.index = pd.to_datetime(data['dt'], format='%d/%m/%Y %H:%M')
data['quality'].plot()
plot.show()

Related

Pandas converting sub-columns into rows

I have added a picture of my dataframe. There are sub-columns names which are 'GBPEUR=X' 'GBPJPY=X' and 'USDMXN=X'. I would like to take these sub-headings and turn them into different rows. Any idea of how to do this as cant find anything else on the internet? Code below:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import yfinance as yf
%matplotlib inline
df = yf.Tickers('GBPJPY=X GBPEUR=X USDMXN=X')
currencies = df.history(period='max')

Pandas23 change the way it treats multindex labels for xticklabels?

This fragment of code demonstrates a problem I've encountered having switched from pandas 0.19.2 to 0.23.0: df.plot() is not correctly converting the multindex to xticklabels.
import pandas as pd
import datetime
import numpy as np
import dateutil.parser
import dateutil.parser
import matplotlib as plt
%matplotlib inline
import platform
print(f"pandas version: {pd.__version__}")
print(f"python version: {platform.python_version()}")
#create the main dataframe
dt = pd.DatetimeIndex(start='2010-1-1', end = '2010-12-31', freq='m')
dt2 = pd.DatetimeIndex(start='2011-1-1', end = '2011-1-10', freq='d')
mi = pd.MultiIndex.from_product([dt,dt2], names=['assessment_date', 'contract_date'])
df = pd.DataFrame(index=mi)
df['foo']=7
df.plot(rot=50)
When I originally used this code, the result looked like:
But now I use pandas 0.23 and the ticklabels are incorrect
Not sure why this is occurring, or where to look for the issue.

factorplot with seaborn python

I try to plot a factorplot with seaborn
Here is my python code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib import style
import pandas as pd
import seaborn as sns
import io
style.use('ggplot')
#load dataset into df2 dataframe
df2 = pd.read_csv('C:/Users/Demonstrator/Downloads/power.csv',delimiter=';')
#drop NaN rows from df2 to build df_no_missing
df_no_missing = df2.dropna().copy()
df_no_missing.head()
df_no_missing['depassement'] = np.where((df_no_missing['P_ACT_KW'] - df_no_missing['P_SOUSCR']) < 0, 0, df_no_missing['P_ACT_KW'] - df_no_missing['P_SOUSCR'])
#build a factorplot
sns.factorplot(data=df_no_missing, x="TIMESTAMP", y="P_ACT_KW")
It is impossible to view a result the process seems busy.

How can I show True/False graph on Python

I have a csv file and I want to show this data on grap. I have date,place and status data but I don't need place so I fetch data like this.
And going like this
Here is my code. How can I get a graph with 1-0 values according to date value. Which method should I use ? Thanks
import pandas as pd from pandas
import DataFrame
import datetime
import pandas.io.data
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d
import Axes3D import pylab rows_list=[] df=pd.read_csv('filepath',header=None,parse_dates=True,pr‌​efix='column')
for row in df.iterrows():
if row[1][1]=='Beweging in de living':
if row[1][2]=='OPEN': rows_list.append([row[1][0],'1'])
else: rows_list.append([row[1][0],'0'])
df2 = pd.DataFrame(rows_list)
df3=df2.set_index(0)
print df3 plt.plot(df3)
plt.show()

How to create box plot from pandas object using matplotlib?

I read data into pandas object and then I want to create a box plot using matplotlib (not pandas.boxplot()). This is just for learning purposes. This is my code, in which myData['MyColumn'] fails.
import matplotlib.pyplot as plt
import pandas as pd
myData = pd.read_csv('data/myData.csv')
plt.boxplot(myData['MyColumn'])
plt.show()
Your code works fine with fake data. Check the type of the data you're trying to plot.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
myData = pd.DataFrame(np.random.rand(10, 2), columns=['MyColumn', 'blah'])
plt.boxplot(myData['MyColumn'])
plt.show()

Categories

Resources