— python, numpy, pandas, e&s — 1 min read
Last updated : 08/August/2020
Events are in reverse chronological order.
Error occurs in this line when trying to convert case to lower.
1df_tc['name'] = df_tc['name'].apply(lambda x: x.lower())2
3# In df_tc.info(), it confirms its an object but executing above line, it fails4name 3754 non-null object
Why this error occured because NaNs are considered as float ? I got to find that by doing
1for row in df_tc.itertuples(): 2 if(type(row.name) is not str):3 print(row.Index, type(row.name))4
5# Output614 <class 'float'>721 <class 'float'>8....9
10df_tc.loc[14]11# Output12dt 2020-07-0313name NaN14cl 0.7615Name: 14, dtype: object
Solution :
1df_tc['name'] = df_tc.name.str.lower()
Installing in Jupyter
1import sys2!{sys.executable} -m pip install lxml3
4**Output** 5Requirement already satisfied: lxml in c:\users\sushanth\appdata\local\programs\python\python35-32\lib\site-packages (4.5.2)
To know where its installed,
1import lxml2lxml.__path__
This error you get even after you have installed everything,
1import lxml2import requests3import html5lib4import BeautifulSoup45
6import sys7!{sys.executable} -m pip install BeautifulSoup4
When you execute the below code,
1url = 'https://en.wikipedia.org/wiki/List_of_elevator_accidents'2tables = pd.read_html(url)3 4print(tables)5
6#Output :7ImportError: lxml not found, please install it
Solution :
You have to Restart Kernel in Jupyter
When looping dataframe trying to get a value from dataframe cell, got the error.
1row[rd_Qcolname]
Solution :
1getattr(row, rd_Qcolname)
Date : 17/April/2020
When executing the below line in pandas, got that error.
1df_temp[df_temp['ts'] > dt_3d]2
3# Error : 4# TypeError: unorderable types: datetime.date() > str()
Analysis
1print(type(df_temp['ts'])) # <class 'pandas.core.series.Series'>2print(type(df_temp['ts'][0])) # <class 'datetime.date'>3print(type(dt_3d)) # <class 'str'>
Update 1 : Updated like below, still got an error.
1df_temp[df_temp['ts'] > pd.to_datetime(dt_3d)]2
3# Error : 4# TypeError: Cannot compare type 'Timestamp' with type 'date'
Solution :
Update 2 : df_temp[df_temp['ts'] > pd.to_datetime(dt_3d).date()]
Worked
1for i in range(10): 2 print(i, end =" ") 3
4---------------------------------------------------------------------------5TypeError Traceback (most recent call last)6<ipython-input-324-e27c647546fc> in <module>7----> 1 for i in range(10):8 2 print(i, end =" ")9
10TypeError: 'tuple' object is not callable
Solution : This took some time to solve. I had used keyword range
as a variable.
1print(range)2
3(201913, 201915)
Solution is del range
and then the loop worked.
1for i in range(10): 2 print(i, end =" ") 3
40 1 2 3 4 5 6 7 8 9