Showing some data that meets certain conditions is a problem in PANDAS

I work in PANDAS with Python and I am watching the weather CSV file. I can extract data from it without problems. However, I cannot retrieve data that meets certain criteria, for example, when I show which days have temperatures above 100 degrees.

I have this as my code:

import pandas as pd
import numpy as np 
import matplotlib.pyplot as plt 

df = pd.read_csv('csv/weather.csv')

print(df[[df.MaxTemperatureF > 100 ]])

In this last line, I think I have my problem. The error tracking that I now get after completing the following steps is as follows:

Traceback (most recent call last):
File "weather.py", line 40, in <module>
print(df[df['MaxTemperatureF' > 100]])
TypeError: unorderable types: str() > int()
Mikes-MBP-2:dataframes mikecuddy$ python3 weather.py
Traceback (most recent call last):
File "weather.py", line 41, in <module>
print(df[[df.MaxTemperatureF > 100 ]])
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-     
packages/pandas/core/frame.py", line 1991, in __getitem__
return self._getitem_array(key)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-  
packages/pandas/core/frame.py", line 2028, in _getitem_array
(len(key), len(self.index)))
 ValueError: Item wrong length 1 instead of 360.

I am doing a tutorial at: http://www.gregreda.com/2013/10/26/working-with-pandas-dataframes/ Again, any help would be great! Thank!

df.info ():

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 360 entries, 0 to 359
Data columns (total 23 columns):
PST                           360 non-null object
MaxTemperatureF               359 non-null float64
Mean TemperatureF             359 non-null float64
Min TemperatureF              359 non-null float64
Max Dew PointF                359 non-null float64
MeanDew PointF                359 non-null float64
Min DewpointF                 359 non-null float64
Max Humidity                  359 non-null float64
Mean Humidity                359 non-null float64
Min Humidity                 359 non-null float64
Max Sea Level PressureIn     359 non-null float64
Mean Sea Level PressureIn    359 non-null float64
Min Sea Level PressureIn     359 non-null float64
Max VisibilityMiles          355 non-null float64
Mean VisibilityMiles         355 non-null float64
Min VisibilityMiles          355 non-null float64
Max Wind SpeedMPH            359 non-null float64
Mean Wind SpeedMPH           359 non-null float64
Max Gust SpeedMPH            211 non-null float64
PrecipitationIn               360 non-null float64
CloudCover                   343 non-null float64
Events                       18 non-null object
WindDirDegrees               360 non-null int64
dtypes: float64(20), int64(1), object(2)
memory usage: 64.8+ KB
None
+4
2

:

df = pd.read_csv('csv/weather.csv', converters={'MaxTemperatureF':float})

: @ptrj , , np.nan MaxTemperatureF:

df = pd.read_csv('csv/weather.csv', 
                 converters={'MaxTemperatureF':
                             lambda x: try: return float(x); 
                                       except ValueError: return np.nan;})

Edit2: @ptrj, ...

def my_conv(x): 
    try: 
        return float(x)
    except ValueError: 
        return np.nan

df = pd.read_csv('csv/weather.csv', converters={'MaxTemperatureF': my_conv})

:

  • csv , header=0.
  • , cols=...
  • sep ',', .
+3

: "()" [].

print(df[df.MaxTemperatureF.astype(float) > 100 ])

:

df.isnull().sum() 
df.dropna()
df.fillna(0) 
+1

All Articles