This question already has answers here:
Output images to html using python
(3 answers)
Dynamically serving a matplotlib image to the web using python
(6 answers)
Closed 4 months ago.
I wrote a function to visualize python graphs using 'Seaborn' & 'Matplotlib' & I have been trying to store the output in HTML files. Is there a way to do so? I looked online but couldn't find any sources that talk about storing the visualizations of these libraries in HTML.
# Importing libraries
from statistics import correlation
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def dynamic_manual_eda(df):
# Visualizing missing values
miss_viz=sns.heatmap(df.isnull(),yticklabels=False,cbar=False,cmap='viridis')
miss_plot=miss_viz.write_html("templates/missing_viz.html")
return miss_plot
eda_file = pd.read_csv('C:/Users/Churn_bank.csv')
dynamic_manual_eda(eda_file)
The error I get here is - '**AttributeError: 'AxesSubplot' object has no attribute 'write_html**''
NOTE: The visualizations should be stored only in HTML files. That's the requirement.
Related
This question already has answers here:
Read .mat files in Python
(15 answers)
reading v 7.3 mat file in python
(9 answers)
Closed last year.
I am trying to import a .mat (not human readable) file in python
I imported it using a package called AT.
import at
from at.plot import plot_beta
import time
import matplotlib.pyplot as plt
r = at.load_mat('FCCee_z_512_nosol_10.mat', key='RING')
Now, I want to access the data inside this .mat file and also to add some values to it using python and to save the updated file in .py format.
The result of printing the r is :
Lattice(<11470 elements>, name='l000015', energy=45600000000.0, particle=Particle('electron'), `periodicity=1, harmonic_number=121657, mat_key='RING', mat_file='N:\\musa\\1\\1\\General-`quistions\\MAD-X_Python\\fccV8_AT\\FCCee_z_512_nosol_10.mat', key='ring')`
Ho can i edit the valus of this file and save in in python format ?
You can use scipy loadmat method to read .mat files.
https://docs.scipy.org/doc/scipy-1.8.0/html-scipyorg/reference/generated/scipy.io.loadmat.html?highlight=loadmat#scipy.io.loadmat
import scipy.io
r = scipy.io.loadmat('FCCee_z_512_nosol_10.mat')
r['data'] # you want to access
This question already has answers here:
Dynamically serving a matplotlib image to the web using python
(6 answers)
Closed 1 year ago.
So I know that i can save my diagramm with
plt.savefig('/home/pi/test.png')
But I don't really know how to save and display my diagramm with a HTML file.
For my website it would be easier use a HTML file to display my data. So is it possible to save my diagramm in HTML and how?
If it helps here is my code:
from pandas import DataFrame
import sqlite3
import matplotlib.pyplot as plt
import pandas as pd
con = sqlite3.connect("/home/pi/test2.db")
df = pd.read_sql_query("SELECT * from data4 limit 79;",con)
df.plot(x = 'zeit', y = 'temp', kind ='line')
plt.savefig('/home/pi/test.png')
#plt.show()
I'm sorry if I did some mistakes I'm a beginner:)
As far as I know that is not possible with matplotlib But it is possible with https://mpld3.github.io/ and specifically this function: https://mpld3.github.io/modules/API.html#mpld3.fig_to_html
mpld3.fig_to_html(fig, d3_url=None, mpld3_url=None, no_extras=False, template_type='general', figid=None, use_http=False, **kwargs)
Output html representation of the figure
This question already has answers here:
Reading an Excel file in python using pandas
(10 answers)
Closed 3 years ago.
I am trying to import data from an excel file. I would like to import from a specific sheet and in that specific sheet only import certain columns.
The code I am using is as follows:
%matplotlib inline
import pandas as pd
import math
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="darkgrid")
# Input Portfolio data
xl_file=pd.ExcelFile('C:/Users/e877780/Desktop/DEV/S2_SK_S_06_02_input.xlsx')
s2_0602=xl_file.parse("S.06.02")[('C0080','C0090')]
My idea is to only import columns C0080 and C0090. I I just use one, it works but also does not keep the column name.
Can someone help
Thks
You can try this:
xl_file=pd.ExcelFile('C:/Users/e877780/Desktop/DEV/S2_SK_S_06_02_input.xlsx')
sheet1=xl_file.parse("S.06.02")
s2_0602 = sheet1[['C0080','C0090']]
Hope it help
This question already has answers here:
Seaborn load_dataset
(4 answers)
why is jupyter notebook not accepting my csv file link? [duplicate]
(1 answer)
Closed last month.
I am trying to utilize Seaborn to create a visualization.
Here is what I have thus far:
import os.path
directory = os.path.dirname(os.path.abspath(__file__))
import pandas as pd
import seaborn as sns
sns.set(style="whitegrid", color_codes=True)
tel = pd.read_csv('nyc.csv')
nyctel = sns.load_dataset(tel)
sns.stripplot(x="installation_id", y="mounting", hue="mounting", data=nyctel)
The official documentation for load_dataset is completely useless, so I found that someone had already asked a question about how it works here: https://stackoverflow.com/a/30337377/6110631
I followed the format listed in the answer and imported pandas so I could use a local file (saved in the same folder). When I run the program however, I get
IOError: File nyc.csv does not exist
If I use an absolute path I get
IOError: ('http protocol error', 0, 'got a bad status line', None)
It seems the problem is with this line:
nyctel = sns.load_dataset(tel)
because if I omit this line and the line beneath it and add print tel beneath the pd.read_csv line then the program works and it prints out the contents of the file. Somehow load_dataset is not letting me use that file though!
I am using the exact same code as in the answer linked above. Why would this not work for this local file?
The load_dataset() is only necessary to create a Pandas DataFrames, out of an example database. In your case, you created a DataFrame whith pd.read_csv('nyc.csv'), so sns.load_dataset(tel) is unnecessary and not working.
Here is a quote from https://seaborn.pydata.org/introduction.html
Most code in the docs will use the load_dataset() function to get
quick access to an example dataset. There’s nothing special about
these datasets: they are just pandas dataframes, and we could have
loaded them with pandas.read_csv() or built them by hand. Most of the
examples in the documentation will specify data using pandas
dataframes, but seaborn is very flexible about the data structures
that it accepts.
I'm posting this via mobile so it's not tested:
import pandas as pd
import seaborn as sns
import os.path
directory = os.path.dirname(os.path.abspath(__file__))
filename = 'nyc.csv'
file_path = os.path.join(directory, filename)
tel = pd.read_csv(file_path)
sns.set(style="whitegrid", color_codes=True)
nyctel = sns.load_dataset(tel)
sns.stripplot(x="installation_id", y="mounting", hue="mounting", data=nyctel)
This question already has answers here:
How to show matplotlib plots?
(6 answers)
Closed 5 years ago.
I have a pandas data frame wit the following properties:
Name: df_name,
Concerned Column: col1
If I want to plot a column, I can execute the following code in python shell(>>>) or ipython notebook.
>>>df_name['col1'].plot(kind='bar')
However, I want to use the same function in a script and execute from command line, the plot doesn't appear.
The script I want to write looks like the following:
import pandas as pd
.
.
.
df_name=pd.read_csv('filename')
# Printing bar chart of 'col1'
df_name['col1'].plot(kind='bar')
Any Ideas how to make it execute from a script?
I think, you need to import matplotlib.pyplot and to use show method like in example.
import pandas as pd
import matplotlib.pyplot as plt
df_name=pd.DataFrame([1,2,3])
df_name[0].plot(kind='bar')
plt.show()