Small business requires many tasks to be completed on PC. With python language you need to learn to integrate many libraries which can run your daily tasks or to code own solutions to outpace competitors. There are billions lines of python codes, so the limit is integrating knowledge and efficiency. To run business you can predict demand, use artificial intelligence to bring leads, automate routines tasks, integrate other programs. From salesmen to scientists use coding. Become curious!
Search This Blog
Showing posts with label pandas. Show all posts
Showing posts with label pandas. Show all posts
Saturday, November 11, 2017
How do I find and remove duplicate rows in pandas?
Great tutorial how to find duplicated rows and remove them either identical or by column. Use drop_dublicates plus column set plus shape methods. See video.
Friday, November 10, 2017
Pandas Data frame update update
Pandas data frame update should be one of the most useful functions.
DataFrame.update(other, join='left', overwrite=True, filter_func=None, raise_conflict=False)[source]¶
Modify DataFrame in place using non-NA values from passed DataFrame. Aligns on indices
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.update.html
Pandas dataframe merge with update data
Pandas dataframe merge with update data
print (pd.concat([df1, df2]).drop_duplicates('date', keep='last')) date value0 2017-01-01 11 2017-01-02 12 2017-01-03 10 2017-01-04 21 2017-01-05 22 2017-01-06 23 2017-01-07 24 2017-01-08 2
Concat works, but drop_dublicates('ID', keep='last') does not.
Labels:
pandas,
pandas data frames updates
Location:
Vilnius, Lithuania
Monday, October 23, 2017
Pandas functions to export data frames
Pandas functions to export merged data frames to various formats became important since after merging in new frame there are repetitive identical values. Therefore, I need to remove multiindexing enumeration rows column and delete identical repetitive lines.
There is bug wheather on my PC or on Pandas function is deprecated, since
index_col=None function is now working.
I test while creating data frames still csv generates multindex rows first enumaration column.
pandas.read_table
Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider index_col=False to force pandas to _not_ use the first column as the index (row names)
So I used pdf.read_table to import text files used delimited "," specification for separation and data frames merge function (still to test best merging function). Pandas brings automation possibilities to constantly update Groups data membership and rules.
On stackoverflow on found right coding to export csv without first row, the right code is result.to_csv('3.csv', index=False).
There is interesting functionality can read into data frame html code. See Pandas API Reference:
read_html(io[, match, flavor, header, ...]) | Read HTML tables into a list of DataFrame objects. |
Here is the right code t export text file result.to_csv(r'pandas.txt', index=None, mode='a') . Mode 'a' is for append text file. So now I can remove repetivtie identical files. There is another capabilities of Pandas to match with code similar by text lines.
Pandas link to_csv function
https://pandas.pydata.org/pandas docs/stable/generated/pandas.Series.to_csv.html
And the final code to export dataframe free from repetitive identical lines is df2.to_csv('facebook_groups_members.csv', index=None). Keep in mind that I did not spend much time reading Pandas documentation. It is worth to do it, to do it since you can revolutionize marketing or economic researches since you can download html to data frame, or scrap with scrapy spider tabel site and process it with python to data frame. And then you code stats analysis.
And the final code to export dataframe free from repetitive identical lines is df2.to_csv('facebook_groups_members.csv', index=None). Keep in mind that I did not spend much time reading Pandas documentation. It is worth to do it, to do it since you can revolutionize marketing or economic researches since you can download html to data frame, or scrap with scrapy spider tabel site and process it with python to data frame. And then you code stats analysis.
Location:
Vilnius, Lithuania
Subscribe to:
Posts (Atom)