chtoolbox 0.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chtoolbox
3
- Version: 0.1
3
+ Version: 0.2.0
4
4
  License-File: LICENSE
@@ -0,0 +1 @@
1
+ from .misc import *
@@ -0,0 +1,56 @@
1
+ import pandas as pd
2
+
3
+ def clipboard_to_dict():
4
+ """
5
+ Converts clipboard content to a dictionary.
6
+ This function reads the clipboard content into a pandas DataFrame and converts it to a dictionary.
7
+ If the DataFrame has two columns, it converts it to a flat dictionary.
8
+ If the DataFrame has more than two columns, it converts it to a nested dictionary with 'index' orientation.
9
+ Returns:
10
+ dict: A dictionary representation of the clipboard content.
11
+
12
+ Example 1:
13
+
14
+ >>> # Copy a range in excel containing thw following to the clipboard:
15
+ idx col_a col_b col_c
16
+ row_a 1 4 7
17
+ row_b 2 5 8
18
+ row_c 3 6 9
19
+
20
+ >>> clipboard_to_dict()
21
+ {'row_a': {'col_a': 1, 'col_b': 4, 'col_c': 7},
22
+ 'row_b': {'col_a': 2, 'col_b': 5, 'col_c': 8},
23
+ 'row_c': {'col_a': 3, 'col_b': 6, 'col_c': 9}}
24
+
25
+ Example 2:
26
+ >>> # Copy a range in excel containing thw following to the clipboard:
27
+ idx col_a
28
+ row_a 1
29
+ row_b 2
30
+ row_c 3
31
+
32
+ >>> clipboard_to_dict()
33
+ {'row_a': 1, 'row_b': 2, 'row_c': 3}
34
+ """
35
+ # Read the clipboard content into a DataFrame
36
+ df = pd.read_clipboard(header=None)
37
+
38
+ if df.shape[1] == 2:
39
+ # Convert the DataFrame to a flat dictionary
40
+ dictionary = dict(zip(df[0], df[1]))
41
+ else:
42
+ # Check if the first column header is empty
43
+ if pd.isna(df.iloc[0, 0]):
44
+ df.columns = ['idx'] + list(df.iloc[0, 1:])
45
+ df = df[1:]
46
+ else:
47
+ df.columns = df.iloc[0]
48
+ df = df[1:]
49
+
50
+ # Set the first column as the index
51
+ df.set_index('idx', inplace=True)
52
+
53
+ # Convert the DataFrame to a nested dictionary with 'index' orientation
54
+ dictionary = df.to_dict(orient='index')
55
+
56
+ return dictionary
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chtoolbox
3
- Version: 0.1
3
+ Version: 0.2.0
4
4
  License-File: LICENSE
@@ -2,7 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  chtoolbox/__init__.py
5
- chtoolbox/main.py
5
+ chtoolbox/misc.py
6
6
  chtoolbox.egg-info/PKG-INFO
7
7
  chtoolbox.egg-info/SOURCES.txt
8
8
  chtoolbox.egg-info/dependency_links.txt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='chtoolbox',
5
- version='0.1',
5
+ version='0.2.0',
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  'numpy',
@@ -1 +0,0 @@
1
- from .main import test_function
@@ -1,2 +0,0 @@
1
- def test_function():
2
- return 42
File without changes
File without changes
File without changes