You can copy paste the csv string in excel or LibreOffice Calc, and then use the "Text to columns" feature.
Then you can save the file and read it back with pd.read_csv
or pd.read_excel
.
Copy paste the csv string in a text editor and save it with a .csv
extension, and read that file with pd.read_csv
.
First, put it in a string
import pandas as pd
import seaborn as sns
import io
sns.set()
csv_string = '''Temperature,Neighbourhood,Salesperson,Route length,Price index,Truck size,Net income
26,Rivendell,Frodo,24,68,Ballrog-sized,51.930832
33,Mordor,Frodo,12,5,Hobbit-sized,68.71245
28,Rivendell,Sam,20,54,Human-sized,-58.581932
18,The Shire,Sam,13,18,Human-sized,-35.673244
22,The Shire,Sméagol,23,50,Ballrog-sized,-252.59929
26,The Shire,Frodo,20,87,Hobbit-sized,54.205677
37,Moria,Sam,40,81,Hobbit-sized,-75.14078
3,The Shire,Bilbo,29,78,Ballrog-sized,-14.662658
27,Mordor,Bilbo,18,45,Human-sized,-130.44525
14,The Shire,Sméagol,5,88,Hobbit-sized,-436.65353
13,Rivendell,Pippin,21,93,Human-sized,178.2662
5,Mordor,Bilbo,32,82,Human-sized,-23.921223
7,Rivendell,Sméagol,5,83,Human-sized,-416.33975
25,The Shire,Sméagol,40,96,Human-sized,-485.17865
3,The Shire,Pippin,34,85,Human-sized,170.53726
33,The Shire,Sméagol,28,37,Ballrog-sized,-178.8795
10,Mordor,Frodo,46,2,Ballrog-sized,20.743103
1,Mordor,Frodo,12,27,Ballrog-sized,2.0371556
22,Rivendell,Pippin,48,21,Hobbit-sized,42.706318
5,Rivendell,Bilbo,5,86,Ballrog-sized,-24.783257
24,The Shire,Sam,16,58,Human-sized,-46.45068
25,Moria,Sméagol,32,90,Ballrog-sized,-437.458
23,The Shire,Bilbo,0,99,Human-sized,-115.94209
2,Moria,Sméagol,23,49,Hobbit-sized,-234.64815
39,Rivendell,Frodo,20,1,Ballrog-sized,75.56986
1,The Shire,Pippin,32,27,Hobbit-sized,54.180164
24,The Shire,Sméagol,0,70,Human-sized,-360.87198
14,Mordor,Bilbo,25,14,Human-sized,-70.079865
38,The Shire,Pippin,15,18,Hobbit-sized,37.45921
30,Rivendell,Pippin,9,34,Human-sized,65.589836
11,Rivendell,Sméagol,26,12,Ballrog-sized,-57.164093
29,Moria,Frodo,28,53,Human-sized,56.198803
10,Mordor,Sméagol,39,11,Ballrog-sized,-56.860405
27,Rivendell,Pippin,18,98,Ballrog-sized,194.34103
30,Mordor,Sméagol,39,95,Human-sized,-470.30716
7,Moria,Sam,17,85,Human-sized,-13.812665
14,The Shire,Pippin,44,66,Human-sized,133.78032
29,Moria,Bilbo,47,22,Human-sized,-138.45506
19,Mordor,Pippin,2,83,Ballrog-sized,159.8335
37,The Shire,Pippin,11,12,Human-sized,23.791155
36,The Shire,Sam,19,63,Ballrog-sized,-70.13689
20,Moria,Sam,35,72,Hobbit-sized,-40.78319
33,Rivendell,Frodo,41,37,Ballrog-sized,64.4895
16,Rivendell,Frodo,24,61,Ballrog-sized,30.687399
32,Rivendell,Frodo,4,17,Hobbit-sized,62.267616
0,Rivendell,Frodo,6,26,Human-sized,0
4,The Shire,Pippin,8,47,Human-sized,95.70522
31,Moria,Pippin,23,72,Hobbit-sized,150.90457
11,Mordor,Frodo,31,4,Ballrog-sized,21.840302
16,The Shire,Bilbo,4,3,Human-sized,-79.58842
35,Mordor,Bilbo,23,86,Human-sized,-167.37378
30,Rivendell,Bilbo,5,7,Human-sized,-145.48619
4,The Shire,Sam,42,59,Ballrog-sized,-7.8863816
32,Mordor,Bilbo,17,56,Hobbit-sized,-154.77057
29,The Shire,Sam,39,78,Ballrog-sized,-55.280235
4,Moria,Frodo,35,5,Hobbit-sized,7.8134522
34,Moria,Bilbo,24,58,Human-sized,-170.45734
13,Rivendell,Frodo,32,42,Hobbit-sized,26.724453
3,Moria,Pippin,35,9,Human-sized,18.717787
26,Rivendell,Sam,30,58,Hobbit-sized,-51.68332
23,Moria,Bilbo,24,67,Ballrog-sized,-117.39741
38,Rivendell,Sam,37,63,Hobbit-sized,-73.308716
23,Moria,Sméagol,1,75,Ballrog-sized,-376.8455
35,Rivendell,Bilbo,0,10,Hobbit-sized,-172.51828
0,Rivendell,Pippin,9,88,Hobbit-sized,178.7064
6,Mordor,Sméagol,38,62,Ballrog-sized,-305.68097
27,Mordor,Bilbo,49,45,Hobbit-sized,-130.41245
26,The Shire,Frodo,6,46,Human-sized,52.693336
26,Moria,Sam,3,81,Hobbit-sized,-49.498913
9,Moria,Sam,13,43,Human-sized,-17.806622
20,The Shire,Bilbo,22,99,Hobbit-sized,-103.69003
19,Mordor,Bilbo,9,34,Human-sized,-96.178246
33,Moria,Sméagol,22,3,Hobbit-sized,-15.287437
8,Moria,Bilbo,28,80,Hobbit-sized,-38.362183
29,Rivendell,Frodo,38,71,Hobbit-sized,59.59328
19,Moria,Sméagol,37,58,Hobbit-sized,-293.0547
13,Rivendell,Frodo,17,24,Hobbit-sized,27.103506
11,Moria,Frodo,34,38,Human-sized,20.993921
8,Moria,Bilbo,43,45,Ballrog-sized,-41.844963
13,Moria,Frodo,4,40,Hobbit-sized,26.118464
31,Moria,Bilbo,8,60,Hobbit-sized,-157.23058
27,Mordor,Frodo,25,96,Human-sized,51.741325
22,The Shire,Sam,36,66,Ballrog-sized,-42.57798
13,Moria,Pippin,11,32,Ballrog-sized,67.075264
14,Rivendell,Pippin,31,51,Ballrog-sized,105.16501
2,Rivendell,Pippin,41,98,Human-sized,200.5796
9,Mordor,Frodo,37,29,Hobbit-sized,17.540604
27,Moria,Pippin,26,52,Human-sized,104.534935
9,The Shire,Bilbo,23,63,Hobbit-sized,-46.195038
30,The Shire,Bilbo,15,78,Ballrog-sized,-148.4144
7,The Shire,Bilbo,35,11,Ballrog-sized,-34.300014
35,Moria,Frodo,26,74,Hobbit-sized,70.368004
11,Rivendell,Pippin,18,52,Ballrog-sized,105.58361
7,Mordor,Sam,44,86,Ballrog-sized,-14.175751
35,The Shire,Pippin,17,91,Human-sized,176.879
6,The Shire,Sam,45,85,Ballrog-sized,-11.626123
9,Mordor,Frodo,2,28,Ballrog-sized,17.872433
37,Moria,Bilbo,44,12,Hobbit-sized,-185.8807
14,The Shire,Bilbo,26,90,Ballrog-sized,-71.49562
26,Rivendell,Sméagol,18,68,Human-sized,-327.78433
'''
Just dump the string in a file and read it back with pd.read_csv
:
with open("IceCream.csv", "w") as f:
f.write(csv_string)
df = pd.read_csv("IceCream.csv")
df.head()
Temperature | Neighbourhood | Salesperson | Route length | Price index | Truck size | Net income | |
---|---|---|---|---|---|---|---|
0 | 26 | Rivendell | Frodo | 24 | 68 | Ballrog-sized | 51.930832 |
1 | 33 | Mordor | Frodo | 12 | 5 | Hobbit-sized | 68.712450 |
2 | 28 | Rivendell | Sam | 20 | 54 | Human-sized | -58.581932 |
3 | 18 | The Shire | Sam | 13 | 18 | Human-sized | -35.673244 |
4 | 22 | The Shire | Sméagol | 23 | 50 | Ballrog-sized | -252.599290 |
With StringIO, pandas
thinks it's reading a file, but the data never reaches the disk and stays in RAM.
df = pd.read_csv(io.StringIO(csv_string))
df.head()
Temperature | Neighbourhood | Salesperson | Route length | Price index | Truck size | Net income | |
---|---|---|---|---|---|---|---|
0 | 26 | Rivendell | Frodo | 24 | 68 | Ballrog-sized | 51.930832 |
1 | 33 | Mordor | Frodo | 12 | 5 | Hobbit-sized | 68.712450 |
2 | 28 | Rivendell | Sam | 20 | 54 | Human-sized | -58.581932 |
3 | 18 | The Shire | Sam | 13 | 18 | Human-sized | -35.673244 |
4 | 22 | The Shire | Sméagol | 23 | 50 | Ballrog-sized | -252.599290 |
sns.displot(data=df, x="Net income")
<seaborn.axisgrid.FacetGrid at 0x7fdbd57587f0>
OK, this does not seem to perfectly fit any well known distribution. Let's see if a categorical variable in the dataset has an influnce:
sns.violinplot(data=df, x="Neighbourhood", y="Net income")
<AxesSubplot:xlabel='Neighbourhood', ylabel='Net income'>
No obvious impact, let's try another one:
sns.violinplot(data=df, x="Salesperson", y="Net income")
<AxesSubplot:xlabel='Salesperson', ylabel='Net income'>
OK now there is clearly an impact. What about continuous variables ?
sns.scatterplot(data=df, x="Temperature", y="Net income")
<AxesSubplot:xlabel='Temperature', ylabel='Net income'>
There are three lines and some noise. Let's be more thorough and check all continuous variables at once:
sns.pairplot(data=df)
<seaborn.axisgrid.PairGrid at 0x7fdbcc802910>
We have linear relationships with temperature and price index. Let's see if the impact of the salesperson we discovered earlier can be also seen here.
sns.pairplot(data=df, hue="Salesperson")
<seaborn.axisgrid.PairGrid at 0x7fdbcbde38e0>
It clearly can. Let's display a graph for, say, a road manned by Sam, in order to find the missing value:
sns.regplot(data=df.query("Salesperson == 'Sam'"), x="Temperature", y="Net income")
<AxesSubplot:xlabel='Temperature', ylabel='Net income'>