Create heating degree days (HDD) column in pandas dataframe [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 5 years ago.
Improve this question
I want to create a heating degree days (HDD) column in a Pandas dataframe, using another column (df.temp) for the temperature.
Here's the formula I'd like to replicate in a Pandas dataframe:
df['hdd'] = max(0, (15 - df.temp))

Try this:
import numpy as np
df['hdd'] = np.maximum(0, (15 - df['temp']))
numpy vectorises calculations, so it applies across the series.

Related

Using Numpy to update one column by the square root of those column values [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 8 months ago.
Improve this question
Given an array update the second column by the square root of those values.
As rafaelc suggested, you can use np.sqrt on a specific column.
a = np.array([[1.,2.,3.],[1.,2.,3.]])
a[:,1] = np.sqrt(a[:,1])
a has two rows and three columns. a[:,1] is the second column.

DropUnwanted Data from 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 a large panel dataset of countries. I want to drop a large number of countries and keep a few only for a certain number of year. What would be the appropriate command?
I can't see your code but you might be able to use boolean masks
newdf = df[(df["Countries"] == "Ireland")|(df["Countries"] == "South Africa")]
newdf = newdf[df["Year"] == 2011]

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 plot graph based on attendance [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 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

Transferring matrices and vectors from R to Python [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 5 years ago.
Improve this question
I have some large matrices and vectors calculated in R. I want to transfer this data to Python (2.7) in order to do some further data analysis.
What is a recommended way to do this?
I am very familiar with R, but a beginner in Python.
Use write.csv(matrix, "~/filename.csv) in R and then in Python either (if you want to use pandas)
import pandas as pd
new_matrix = pd.read_csv("~/filename.csv")
or (if you want to use numpy)
import numpy as np
new_matrix = np.genfromtxt("~/filename.csv", delimiter = ",")

Categories