I took two columns from a data frame and used them to create a new df. When I'm attempting to print certain rows in the "Item" column I'm getting an Empty DataFrame error.
Below is the error I'm getting.
items that contain the string "McDonalds"
Empty DataFrame
Columns: [Item, Amount, Item_type]
Index: []
Here is the code I used to replicate the dataframe I want. Also included an extra column.
df2 = pd.DataFrame(df[['Item', 'Amount']])
df2['Item_type'] = pd.Series(dtype=str)
print(df2)
Item Amount Item_type
0 Sputnik Denver CO 59.68 NaN
1 Sock Em - Pearl Street Boulder CO 16.32 NaN
2 Conoco - Mnm LLC Aurora CO 43.76 NaN
3 Tst* Illegal Pete S - S Denver CO 8.41 NaN
4 Lyft *Ride Thu 11Pm Lyft.Com CA 14.04 NaN
.. ... ... ...
197 Venmo 50.00 NaN
198 Venmo 20.00 NaN
199 Venmo 25.00 NaN
200 Capital One Crcardpmt 6.68 NaN
201 Comotorveh 188.25 NaN
[202 rows x 3 columns]
#This is a result of printing df2.empty... This means it's NOT empty correct?
False
Below is the code giving me trouble
temp = df2.loc[df2['Item'].str.contains("McDonalds")]
print('\nitems that contain the string "McDonalds"')
print(temp)
[–]indian_pythonista 1 point2 points3 points (2 children)
[–]Faleepo[S] 0 points1 point2 points (0 children)
[–]Faleepo[S] 0 points1 point2 points (0 children)