Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to deal with SettingWithCopyWarning in Pandas

return (
    pd.read_csv(StringIO(str_of_all), sep=',', names=list('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg')) #dtype={'A': object, 'B': object, 'C': np.float64}
    .rename(columns={'A':'STK', 'B':'TOpen', 'C':'TPCLOSE', 'D':'TPrice', 'E':'THigh', 'F':'TLow', 'I':'TVol', 'J':'TAmt', 'e':'TDate', 'f':'TTime'}, inplace=True)
    .ix[:,[0,3,2,1,4,5,8,9,30,31]]
    .assign(
        TClose=lambda df: df['TPrice'],
        RT=lambda df: 100 * (df['TPrice']/quote_df['TPCLOSE'] - 1),
        TVol=lambda df: df['TVol']/TVOL_SCALE,
        TAmt=lambda df: df['TAmt']/TAMT_SCALE,
        STK_ID=lambda df: df['STK'].str.slice(13,19),
        STK_Name=lambda df: df['STK'].str.slice(21,30)#.decode('gb2312'),
        TDate=lambda df: df.TDate.map(lambda x: x[0:4]+x[5:7]+x[8:10]),
            )
)
'''
Using Assign. From the documentation: Assign new columns to a DataFrame, returning a 
new object (a copy) with all the original columns in addition to the new ones.

See Tom Augspurger's article on method chaining in pandas:
https://tomaugspurger.github.io/method-chaining
'''
Comment

PREVIOUS NEXT
Code Example
Python :: plotly two y axis bar chart 
Python :: prevent not admin from visiting a url tornado python 
Python :: keras imagenet 
Python :: Convert Time object to String in python 
Python :: How to provide type hinting in UserDict 
Python :: In addition to indexing, slicing is also supported. While indexing is used to obtain individual characters, slicing allows you to obtain substring: 
Python :: pip package dynamic setup.py example 
Python :: Histograms without overlapping bars 
Python :: django save object 
Python :: truncated float python 
Python :: NLP text summarization preprocess and tokenization 
Python :: python regular expression path 
Python :: added variable plot python 
Python :: web3.eth.personal.newAccount(password, [callback]) 
Python :: set DJANGO_SETTINGS_MODULE=mysite.settings django-admin 
Python :: Odoo Module ACL(Access Controls List) 
Python :: rpi pip3 installieren 
Python :: base64 encode image in python 
Python :: change dimension position of numpy array 
Python :: python print install directory 
Python :: Custom x, y-ticks using ax 
Python :: how to increase width of line in graph of linear regression in matplotlib 
Python :: how to get scrapy output file in xml file 
Python :: examples of function decorators in Python 
Python :: give utton a number python 
Python :: python iterar claves 
Python :: python: subset top 5 values in a column 
Python :: inject dynamic value into string python 
Python :: django cms create page programmatically 
Python :: what are the mouseX/mouseY variebles in pycharm 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =