Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PANDAS
#1
i have used this certain method in my script, dtypes,
for some reason it gives one more column info, even though this column is not visible...(nor exists to the best of my knowledge)...

here's the output:

Output:
[5322 rows x 4 columns] unnamed int64 Ticker object Description object Unnamed: 3 object dtype: object
in this output - Unnamed: 3 object - where does it come from ?
likes this post
Reply
#2
(Nov-27-2022, 04:55 PM)astral_travel Wrote: for some reason it gives one more column info, even though this column is not visible...(nor exists to the best of my knowledge)...
It can come from empty data from file you read in.
Do df.columns will show all columns.
To clean up.
df.drop(df.filter(regex="Unname"), axis=1, inplace=True)
Reply
#3
(Nov-27-2022, 06:42 PM)snippsat Wrote:
(Nov-27-2022, 04:55 PM)astral_travel Wrote: for some reason it gives one more column info, even though this column is not visible...(nor exists to the best of my knowledge)...
It can come from empty data from file you read in.
Do df.columns will show all columns.
To clean up.
df.drop(df.filter(regex="Unname"), axis=1, inplace=True)

okay, it sure shows it, but it does not show in the file....here's the output:

Output:
Index(['unnamed', 'Ticker', 'Description', 'Unnamed: 3'], dtype='object')
and attached is the file
Reply
#4
(Nov-27-2022, 08:56 PM)astral_travel Wrote: okay, it sure shows it, but it does not show in the file....here's the output:
Do not need output after you have messed with it,post as sample of input .csv that you taker in.
Reply
#5
okay, so i attached the file...there you can clearly see there's no such column
Reply
#6
(Nov-27-2022, 10:08 PM)astral_travel Wrote: okay, so i attached the file...there you can clearly see there's no such column
Don't see any file,only allstocks.csv that seems like output from Pandas.
I mean the raw file that you take in.
Reply
#7
(Nov-27-2022, 10:22 PM)snippsat Wrote:
(Nov-27-2022, 10:08 PM)astral_travel Wrote: okay, so i attached the file...there you can clearly see there's no such column
Don't see any file,only allstocks.csv that seems like output from Pandas.
I mean the raw file that you take in.

okay, here it is (i had to remove some data so it fits within the forum's limitation (250kb). but the columns's headers are in their place)

Attached Files

.csv   allstocks-original.csv (Size: 14.79 KB / Downloads: 1)
Reply
#8
If want only Ticker and Description columns,can do i like this.
import pandas as pd

df = pd.read_csv('allstocks-original.csv')
df1 = df.iloc[:, :2]
df1.to_csv('stock.csv', index=False)
>>> df1.columns
Index(['Ticker', 'Description'], dtype='object')
>>> 
>>> df1.head()
  Ticker                             Description
0      A              Agilent Technologies, Inc.
1     AA                       Alcoa Corporation
2   AAAU  Goldman Sachs Physical Gold ETF Shares
3   AABB                    Asia Broadband, Inc.
4  AAGFF                   Aftermath Silver Ltd.
Reply
#9
yea that i already understood,
i've been just wondering where that fourth column came from when typing dtypes as it is not visible anywhere....

any idea ?

ah alright snippsat i just saw you already answered this, thank you !
Reply
#10
FYI: You may already be aware of this, but if not, I'd like to share.
The best (IMHO) place to get elementary stock information, much of it for free, all for a very reasonable annual fee is here: https://www.eoddata.com/

If you want intraday quotes, you can scan the robots.txt file to get the sitemap link.
Then drill down wntil you come to the URL that will give you the quote.
Ticker symbols can be downloaded, get then in the end of day data.

You can get information for the following markets:
AMEX, ASX, CFE, EUREX, FOREX, HKEX, INDEX, LIFFE, LSE, MGEX, NASDAQ, NYBOT, NYSE, OTCBB, SGX, TSX, TSXV, USMF, and WCE

Historical data, see: https://www.eoddata.com/products/historicaldata.aspx

see:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020