How can I show True/False graph on Python - 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()

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')

Taking data from specific columns in a dataset

I need to take data from only 3 columns in my dataset, how do I do this? I am trying to make a correlation graph. This is my code:
import matplotlib.pyplot as plt
import pandas as pd
crimedata = pd.read_csv('MasterFileCSV.csv')
crime_df = pd.DataFrame(crimedata)
plt.matshow(crime_df.corr())
plt.show

How to save dataframe without an index

import numpy as np
import pandas as pd
from pandas import ExcelWriter
import matplotlib.pyplot as plt
liste = pd.read_excel("testListe.xlsx")
#delete the numbering column in dataframe
liste.to_excel("output.xlsx")
It seems like you want to save without index:
liste.to_excel("output.xlsx", index=False)

Python: Iris Data Set, include the species

I have the below code and it returns me the min and max values of the chosen column, however, I would also like to include the species that this value relates to. I have also included the column names in the csv file.
import pandas as pd
import numpy as np
import scipy as sp
import matplotlib as mpl
import seaborn as sns
df = pd.read_csv("iris head.csv")
print(min(df['Sepal Length']))
print(max(df['Sepal Length']))
IIUC is as follows:
df.groupby(['class'])['Sepal Length'].agg(['max','min'])

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