I am new to python and I am having some issues to plot my dates from a csv file.
The code is the following:
import pandas as pd
import numpy as np
import statsmodels.api as sm
from pandas import DataFrame
import matplotlib.pyplot as plt
df = pd.read_csv(r"file.csv",index_col=0)
print(df.describe())
BHSI_cycle, BHSI_trend = sm.tsa.filters.hpfilter(df['BHSI-TCA'])
df['BHSI_trend'] = BHSI_trend
df['BHSI_cycle'] = BHSI_cycle
BHSI_plot = df[['BHSI-TCA','BHSI_trend']].plot(figsize=(12,10))
plt.show(BHSI_plot)
BHSI_plot2 = df[['BHSI_cycle']].plot(figsize=(12,10))
plt.show(BHSI_plot2)
And the CSV file is:
Date BHSI-TCA
23/05/2006 14821
25/05/2006 14878
30/05/2006 14837
How can I plot the dates?
Try parsing dates properly when you import from csv.
df = pd.read_csv(r"file.csv", index_col=0, parse_dates=<your_date_column>)
Related
I cannot create a full boxplot from my CSV file with pandas and matplotlib in Python.
This is what I get:
My CSV file:
id,type_EN,nb_EN
1,VP,15
2,VN,600
3,FP,78
4,FN,17
5,NOK,974
My code:
# import the required library
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
# load the dataset
df = pd.read_csv("boxplot.csv")
# display 5 rows of dataset
# df.head()
# print the boxplot
df.boxplot(by ="type_EN", column =["nb_EN"], grid = False)
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')
I have a .txt_file showing dates and runoff from 1985-2018 for one station in Norway.
I need to make a plot of the runoff in all July-months.
Here is my code:
from pandas import read_csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import cartopy
from datetime import date,datetime
dir1 = "mystations/"
files = os.listdir(dir1)
files = np.sort(files)
files_txt = [i for i in files if i.endswith('.txt_')]
df = pd.read_csv(dir1+files_txt[0],skiprows=6,header=None, index_col=0,sep=" ",na_values=-9999, parse_dates = True)
df.index = pd.to_datetime(df.index,format="%Y%m%d/%H%M")
myperiod = df["1985":"2018"]
myperiod
and my code prints out a table with the dates and the following runoff values for all years and all months.
enter image description here
How do I plot only runoff for July-month?
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)
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,prefix='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()