Skip to content

Instantly share code, notes, and snippets.

View KobaKhit's full-sized avatar
🏀

Koba Khitalishvili KobaKhit

🏀
View GitHub Profile
@KobaKhit
KobaKhit / hmtl_table_parser.py
Last active July 18, 2022 07:25
Parse all html tables on a page and return them as a list of pandas dataframes. Modified from @srome
# http://srome.github.io/Parsing-HTML-Tables-in-Python-with-BeautifulSoup-and-pandas/
class HTMLTableParser:
@staticmethod
def get_element(node):
# for XPATH we have to count only for nodes with same type!
length = len(list(node.previous_siblings)) + 1
if (length) > 1:
return '%s:nth-child(%s)' % (node.name, length)
else:
return node.name
@KobaKhit
KobaKhit / Large dataframe to csv in chunks in R
Last active September 7, 2017 19:56
Write a large dataframe to csv in chunks
df = read.csv("your-df.csv")
# Number of items in each chunk
elements_per_chunk = 100000
# List of vectors [1] 1:100000, [2] 100001:200000, ...
l = split(1:nrow(df), ceiling(seq_along(1:nrow(df))/elements_per_chunk))
# Write large data frame to csv in chunks
fname = "inventory-cleaned.csv"
@KobaKhit
KobaKhit / reddit-posts.html
Last active August 29, 2015 14:11
A list of top ten posts from a subreddit using redditjs api. Working jsfiddle http://jsfiddle.net/KobaKhit/t42zkbnk/
<!-- Produces a responsive list of top ten posts from a subreddit /worldnews. Working jsfiddle http://jsfiddle.net/KobaKhit/t42zkbnk/ -->
<div id="posts">
<h2> Today's top ten news <small>from <a href = '//reddit.com/r/worldnews' target = '_blank'>/r/worldnews</a></small></h2>
<hr>
<ul class="list-unstyled"></ul>
</div>
<!-- JS -->
<script src="https://rawgit.com/sahilm/reddit.js/master/reddit.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>