how to plot graph based on attendance [closed] - python
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a csv file that contains the attendance of a few students on particular dates.
Here is my csv file
Name,RollNumber,Attendance,Date,Day,Time
student1,1,Present,1/30/2019,Wednesday,12:34:05
student2,2,Present,1/30/2019,Wednesday,12:34:05
student3,3,Present,1/30/2019,Wednesday,12:34:05
student4,4,Present,1/30/2019,Wednesday,12:34:05
student1,1,Absent,1/31/2019,Thursday,23:34:05
student2,2,Present,1/31/2019,Thursday,23:34:05
student3,3,Present,1/31/2019,Thursday,23:34:05
student4,4,Present,1/31/2019,Thursday,12:34:05
student1,1,Present,2/1/2019,Friday,12:34:05
student2,2,Absent,2/1/2019,Friday,12:34:05
student3,3,Absent,2/1/2019,Friday,12:34:05
student4,4,Present,2/1/2019,Friday,12:34:05
student1,1,Absent,2/2/2019,Saturday,12:34:05
student2,2,Absent,2/2/2019,Saturday,12:34:05
student3,3,Absent,2/2/2019,Saturday,12:34:05
student4,4,Absent,2/2/2019,Saturday,12:34:05
I want to plot a graph that show the number of students present and absent on each date from the csv file. How do I do this with matplotlib?
The easiest way in my opinion is to work with pandas pivot_table as follow:
df = pd.read_csv('your_csv_filepath_here')
# Create a duplicate of your target value
df['attendance'] = a.Attendance
# Pivot your dataframe
df_pivot = df.pivot_table(index=['Date'], columns='Attendance', values='attendance', aggfunc='count')
# Plot it using pandas (barplot is probably what you want)
df_pivot.plot(kind='bar')
Of course further plot customizations are possible, as well as other methods would achieve the same result
Related
How can I best split this entry into searchable words? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 months ago. Improve this question This is a picture of my dataset this dataset is from Kaggle here the link to it: https://www.kaggle.com/code/gleblevankov/exploring-spotify-data The type of the column is object, and I want to split/transform this column into a list with words which could be also searchable. I do want to split the column after every "," to get the word. I am somehow searching for a function which could create the words in the column into a list of searchable words pro row. So for example if I want to plot the column to see which genre is the most used one to not see genre like "rap,pop,kpop" but more "rap" "pop" "k-pop" instead. I tried to change the type to list but then it aggregates the whole column into a list. Is there another possible action on how I could transform this column?
Try running this command: import pandas as pd pd.Series([x for item in df.Genere for x in item]).value_counts()
Extract certain values from different columns in dataframe [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question I have an excel sheet and I want to extract different values from different columns into a single columns. desired excel sheet format I want to figure out first of all how to deal with subheaders like astro and athens grey as well as to extract information in this patterns. Thanks sample output I have managed to resolve the sub header issue , Now i just want help with regex to extract information in desired format. Here is what I have done so far ,Subheaders
See if it helps: import pandas as pd data = pd.read_excel('Sample.xlsx') data[data.isna().sum(axis=1)==6] data = data.dropna(how='all') import numpy as np data['SKU'].astype(str).str.extract('([^\(\)]*)')[0].str.strip().replace('\d+', np.nan, regex = True).fillna(method='ffill')+' '+data['DESCRIPTION']+' '+data['SIZE'].str.extract('([^0-9x]+)').fillna('')[0] Output:
I'm looking for how to recreate a similar chart in Python [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I'm looking for a way to create a graph like this but in Python where it's like a stacked bar chart but each segment is in it's own column. This was created in Tableau with the aggregate and one dimension in the columns section and the other variable as rows. I've been looking for awhile to no avail, any help would be greatly appreciated.
You can get something similar to your picture using df.style.bar, e.g.: df.style.bar(subset=['Col_1', 'Col_2', 'Col_3', 'Col_4', 'Col_5'], width=75, vmin=0, color='lightgreen') For a few initial rows from your sample I got the following result: Search the Web for documentation of this function and experiment with changes in its parameters.
what does the pd.read.csv in python turn your data to [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question i have used pandas to read the csv file already i have some questions, is the csv file been set to be some sort of list, or do i have to store the data? i used df = pd.read.cv bla2
Your df would be a pandas dataframe object that includes all of the data.
As others have mentioned the data will be loaded as a DataFrame. I believe the correct syntax you are after is: df = pd.read_csv('data.csv')
How to read a csv file with multiple header rows into pandas? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question I am not sure how to read the multiple rows. Do i have to do it without the rows and then do it manually in pandas? Or is there a way to read the whole csv file into pandas? This is how the file looks Poverty data
You need parameter header=[0,1] in read_csv.