[Tutor] Python and pandas: Convert a column in CSV file to integer
Alan Gauld
alan.gauld at yahoo.co.uk
Sun Sep 20 14:29:37 EDT 2020
On 20/09/2020 17:44, Bvssrs Guntur wrote:
> My requirement is to read a csv file with columns: Date, Maximum
> temperature (TMAX), Min temperature(TMIN) Later I need to summarize by
> quarter and plot a bar graph.
>
> I am using the below code but it is not working.
>
>
> #importing necessary librariesimport pandas as pdimport matplotlib.pyplot as plt
> #Reading the file using pandas
This list is for the Python language and standard library.
pandas is not part of that so you will be reliant on finding
someone here who uses Pandas. You might have more success
asking on the Scipy forums since there will be more pandas
users there.
But...
> df = pd.read_csv(r"C:\Users\home\Downloads\2285297.csv", parse_dates = ['DATE'])
> # Reading each column
> np_maxtemp= df.loc[:,['TMAX']]
> np_mintemp= df.loc[:,['TMIN']]
> np_date= df.loc[:,['DATE']]
> First line itself is giving an error: TypeError: float() argument must
> be a string or a number, not 'Period'
Help yourself by always showing the entire error message not just the
last line. There is a heap of useful information in those messages.
As for the error, I can't help, it makes no sense to me because I don't
know what arguments the pandas function expects. But the parse dates
argument looks suspicious - a list of strings(column labels?)? Is that
right?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list